OxyWindow.ps1
Set-StrictMode -Version 3 function New-OxyWindow { [cmdletbinding()] [OutputType([Windows.Window])] param( [System.Windows.Shell.TaskbarItemInfo]$TaskbarItemInfo, [bool]$AllowsTransparency, [string]$Title, [System.Windows.Media.ImageSource]$Icon, [System.Windows.SizeToContent]$SizeToContent, [double]$Top, [double]$Left, [System.Windows.WindowStartupLocation]$WindowStartupLocation, [bool]$ShowInTaskbar, [System.Windows.Window]$Owner, [System.Nullable[bool]]$DialogResult, [System.Windows.WindowStyle]$WindowStyle, [System.Windows.WindowState]$WindowState, [System.Windows.ResizeMode]$ResizeMode, [bool]$Topmost, [bool]$ShowActivated, [System.Object]$Content, [System.Windows.DataTemplate]$ContentTemplate, [System.Windows.Controls.DataTemplateSelector]$ContentTemplateSelector, [string]$ContentStringFormat, [System.Windows.Media.Brush]$BorderBrush, [System.Windows.Thickness]$BorderThickness, [System.Windows.Media.Brush]$Background, [System.Windows.Media.Brush]$Foreground, [System.Windows.Media.FontFamily]$FontFamily, [double]$FontSize, [System.Windows.FontStretch]$FontStretch, [System.Windows.FontStyle]$FontStyle, [System.Windows.FontWeight]$FontWeight, [System.Windows.HorizontalAlignment]$HorizontalContentAlignment, [System.Windows.VerticalAlignment]$VerticalContentAlignment, [int]$TabIndex, [bool]$IsTabStop, [System.Windows.Thickness]$Padding, [System.Windows.Controls.ControlTemplate]$Template, [System.Windows.Style]$Style, [bool]$OverridesDefaultStyle, [bool]$UseLayoutRounding, [System.Windows.ResourceDictionary]$Resources, [System.Object]$DataContext, [System.Windows.Data.BindingGroup]$BindingGroup, [System.Windows.Markup.XmlLanguage]$Language, [string]$Name, [System.Object]$Tag, [System.Windows.Input.InputScope]$InputScope, [System.Windows.Media.Transform]$LayoutTransform, [double]$Width, [double]$MinWidth, [double]$MaxWidth, [double]$Height, [double]$MinHeight, [double]$MaxHeight, [System.Windows.FlowDirection]$FlowDirection, [System.Windows.Thickness]$Margin, [System.Windows.HorizontalAlignment]$HorizontalAlignment, [System.Windows.VerticalAlignment]$VerticalAlignment, [System.Windows.Style]$FocusVisualStyle, [System.Windows.Input.Cursor]$Cursor, [bool]$ForceCursor, [System.Object]$ToolTip, [System.Windows.Controls.ContextMenu]$ContextMenu, [bool]$AllowDrop, [System.Windows.Size]$RenderSize, [System.Windows.Media.Transform]$RenderTransform, [System.Windows.Point]$RenderTransformOrigin, [double]$Opacity, [System.Windows.Media.Brush]$OpacityMask, [System.Windows.Media.Effects.BitmapEffect]$BitmapEffect, [System.Windows.Media.Effects.Effect]$Effect, [System.Windows.Media.Effects.BitmapEffectInput]$BitmapEffectInput, [System.Windows.Media.CacheMode]$CacheMode, [string]$Uid, [System.Windows.Visibility]$Visibility, [bool]$ClipToBounds, [System.Windows.Media.Geometry]$Clip, [bool]$SnapsToDevicePixels, [bool]$IsEnabled, [bool]$IsHitTestVisible, [bool]$Focusable, [bool]$IsManipulationEnabled, [Hashtable]$Options = @{} ) $OptionHash = @{ Title = "OxyPlot CLI" } foreach ($key in $Options.Keys) { $OptionHash.$key = $Options[$key] } if ($PSBoundParameters.ContainsKey('TaskbarItemInfo')) { $OptionHash.TaskbarItemInfo = $TaskbarItemInfo } if ($PSBoundParameters.ContainsKey('AllowsTransparency')) { $OptionHash.AllowsTransparency = $AllowsTransparency } if ($PSBoundParameters.ContainsKey('Title')) { $OptionHash.Title = $Title } if ($PSBoundParameters.ContainsKey('Icon')) { $OptionHash.Icon = $Icon } if ($PSBoundParameters.ContainsKey('SizeToContent')) { $OptionHash.SizeToContent = $SizeToContent } if ($PSBoundParameters.ContainsKey('Top')) { $OptionHash.Top = $Top } if ($PSBoundParameters.ContainsKey('Left')) { $OptionHash.Left = $Left } if ($PSBoundParameters.ContainsKey('WindowStartupLocation')) { $OptionHash.WindowStartupLocation = $WindowStartupLocation } if ($PSBoundParameters.ContainsKey('ShowInTaskbar')) { $OptionHash.ShowInTaskbar = $ShowInTaskbar } if ($PSBoundParameters.ContainsKey('Owner')) { $OptionHash.Owner = $Owner } if ($PSBoundParameters.ContainsKey('DialogResult')) { $OptionHash.DialogResult = $DialogResult } if ($PSBoundParameters.ContainsKey('WindowStyle')) { $OptionHash.WindowStyle = $WindowStyle } if ($PSBoundParameters.ContainsKey('WindowState')) { $OptionHash.WindowState = $WindowState } if ($PSBoundParameters.ContainsKey('ResizeMode')) { $OptionHash.ResizeMode = $ResizeMode } if ($PSBoundParameters.ContainsKey('Topmost')) { $OptionHash.Topmost = $Topmost } if ($PSBoundParameters.ContainsKey('ShowActivated')) { $OptionHash.ShowActivated = $ShowActivated } if ($PSBoundParameters.ContainsKey('Content')) { $OptionHash.Content = $Content } if ($PSBoundParameters.ContainsKey('ContentTemplate')) { $OptionHash.ContentTemplate = $ContentTemplate } if ($PSBoundParameters.ContainsKey('ContentTemplateSelector')) { $OptionHash.ContentTemplateSelector = $ContentTemplateSelector } if ($PSBoundParameters.ContainsKey('ContentStringFormat')) { $OptionHash.ContentStringFormat = $ContentStringFormat } if ($PSBoundParameters.ContainsKey('BorderBrush')) { $OptionHash.BorderBrush = $BorderBrush } if ($PSBoundParameters.ContainsKey('BorderThickness')) { $OptionHash.BorderThickness = $BorderThickness } if ($PSBoundParameters.ContainsKey('Background')) { $OptionHash.Background = $Background } if ($PSBoundParameters.ContainsKey('Foreground')) { $OptionHash.Foreground = $Foreground } if ($PSBoundParameters.ContainsKey('FontFamily')) { $OptionHash.FontFamily = $FontFamily } if ($PSBoundParameters.ContainsKey('FontSize')) { $OptionHash.FontSize = $FontSize } if ($PSBoundParameters.ContainsKey('FontStretch')) { $OptionHash.FontStretch = $FontStretch } if ($PSBoundParameters.ContainsKey('FontStyle')) { $OptionHash.FontStyle = $FontStyle } if ($PSBoundParameters.ContainsKey('FontWeight')) { $OptionHash.FontWeight = $FontWeight } if ($PSBoundParameters.ContainsKey('HorizontalContentAlignment')) { $OptionHash.HorizontalContentAlignment = $HorizontalContentAlignment } if ($PSBoundParameters.ContainsKey('VerticalContentAlignment')) { $OptionHash.VerticalContentAlignment = $VerticalContentAlignment } if ($PSBoundParameters.ContainsKey('TabIndex')) { $OptionHash.TabIndex = $TabIndex } if ($PSBoundParameters.ContainsKey('IsTabStop')) { $OptionHash.IsTabStop = $IsTabStop } if ($PSBoundParameters.ContainsKey('Padding')) { $OptionHash.Padding = $Padding } if ($PSBoundParameters.ContainsKey('Template')) { $OptionHash.Template = $Template } if ($PSBoundParameters.ContainsKey('Style')) { $OptionHash.Style = $Style } if ($PSBoundParameters.ContainsKey('OverridesDefaultStyle')) { $OptionHash.OverridesDefaultStyle = $OverridesDefaultStyle } if ($PSBoundParameters.ContainsKey('UseLayoutRounding')) { $OptionHash.UseLayoutRounding = $UseLayoutRounding } if ($PSBoundParameters.ContainsKey('Resources')) { $OptionHash.Resources = $Resources } if ($PSBoundParameters.ContainsKey('DataContext')) { $OptionHash.DataContext = $DataContext } if ($PSBoundParameters.ContainsKey('BindingGroup')) { $OptionHash.BindingGroup = $BindingGroup } if ($PSBoundParameters.ContainsKey('Language')) { $OptionHash.Language = $Language } if ($PSBoundParameters.ContainsKey('Name')) { $OptionHash.Name = $Name } if ($PSBoundParameters.ContainsKey('Tag')) { $OptionHash.Tag = $Tag } if ($PSBoundParameters.ContainsKey('InputScope')) { $OptionHash.InputScope = $InputScope } if ($PSBoundParameters.ContainsKey('LayoutTransform')) { $OptionHash.LayoutTransform = $LayoutTransform } if ($PSBoundParameters.ContainsKey('Width')) { $OptionHash.Width = $Width } if ($PSBoundParameters.ContainsKey('MinWidth')) { $OptionHash.MinWidth = $MinWidth } if ($PSBoundParameters.ContainsKey('MaxWidth')) { $OptionHash.MaxWidth = $MaxWidth } if ($PSBoundParameters.ContainsKey('Height')) { $OptionHash.Height = $Height } if ($PSBoundParameters.ContainsKey('MinHeight')) { $OptionHash.MinHeight = $MinHeight } if ($PSBoundParameters.ContainsKey('MaxHeight')) { $OptionHash.MaxHeight = $MaxHeight } if ($PSBoundParameters.ContainsKey('FlowDirection')) { $OptionHash.FlowDirection = $FlowDirection } if ($PSBoundParameters.ContainsKey('Margin')) { $OptionHash.Margin = $Margin } if ($PSBoundParameters.ContainsKey('HorizontalAlignment')) { $OptionHash.HorizontalAlignment = $HorizontalAlignment } if ($PSBoundParameters.ContainsKey('VerticalAlignment')) { $OptionHash.VerticalAlignment = $VerticalAlignment } if ($PSBoundParameters.ContainsKey('FocusVisualStyle')) { $OptionHash.FocusVisualStyle = $FocusVisualStyle } if ($PSBoundParameters.ContainsKey('Cursor')) { $OptionHash.Cursor = $Cursor } if ($PSBoundParameters.ContainsKey('ForceCursor')) { $OptionHash.ForceCursor = $ForceCursor } if ($PSBoundParameters.ContainsKey('ToolTip')) { $OptionHash.ToolTip = $ToolTip } if ($PSBoundParameters.ContainsKey('ContextMenu')) { $OptionHash.ContextMenu = $ContextMenu } if ($PSBoundParameters.ContainsKey('AllowDrop')) { $OptionHash.AllowDrop = $AllowDrop } if ($PSBoundParameters.ContainsKey('RenderSize')) { $OptionHash.RenderSize = $RenderSize } if ($PSBoundParameters.ContainsKey('RenderTransform')) { $OptionHash.RenderTransform = $RenderTransform } if ($PSBoundParameters.ContainsKey('RenderTransformOrigin')) { $OptionHash.RenderTransformOrigin = $RenderTransformOrigin } if ($PSBoundParameters.ContainsKey('Opacity')) { $OptionHash.Opacity = $Opacity } if ($PSBoundParameters.ContainsKey('OpacityMask')) { $OptionHash.OpacityMask = $OpacityMask } if ($PSBoundParameters.ContainsKey('BitmapEffect')) { $OptionHash.BitmapEffect = $BitmapEffect } if ($PSBoundParameters.ContainsKey('Effect')) { $OptionHash.Effect = $Effect } if ($PSBoundParameters.ContainsKey('BitmapEffectInput')) { $OptionHash.BitmapEffectInput = $BitmapEffectInput } if ($PSBoundParameters.ContainsKey('CacheMode')) { $OptionHash.CacheMode = $CacheMode } if ($PSBoundParameters.ContainsKey('Uid')) { $OptionHash.Uid = $Uid } if ($PSBoundParameters.ContainsKey('Visibility')) { $OptionHash.Visibility = $Visibility } if ($PSBoundParameters.ContainsKey('ClipToBounds')) { $OptionHash.ClipToBounds = $ClipToBounds } if ($PSBoundParameters.ContainsKey('Clip')) { $OptionHash.Clip = $Clip } if ($PSBoundParameters.ContainsKey('SnapsToDevicePixels')) { $OptionHash.SnapsToDevicePixels = $SnapsToDevicePixels } if ($PSBoundParameters.ContainsKey('IsEnabled')) { $OptionHash.IsEnabled = $IsEnabled } if ($PSBoundParameters.ContainsKey('IsHitTestVisible')) { $OptionHash.IsHitTestVisible = $IsHitTestVisible } if ($PSBoundParameters.ContainsKey('Focusable')) { $OptionHash.Focusable = $Focusable } if ($PSBoundParameters.ContainsKey('IsManipulationEnabled')) { $OptionHash.IsManipulationEnabled = $IsManipulationEnabled } New-WpfWindow -Options $OptionHash } function Close-OxyWindow { [cmdletbinding()] [OutputType([void])] param( [int]$Index = -1, [switch]$All ) if ($All) { foreach ($w in (Get-OxyWindowList)) { Close-WpfWindow $w } } else { $w = Get-OxyWindow $Index Close-WpfWindow $w } } function Get-OxyWindow { [cmdletbinding()] [OutputType([Windows.Window])] param( [int]$Index = -1 ) $list = Get-OxyWindowList if ($null -eq $list) { Write-Error "No active OxyPlot windows" return } $list = @($list) if ($Index = -1) { $Index = $list.Count - 1 } if ($Index -lt 0 -or $list.Count -le $Index) { Write-Error "Window index out of range" return } $list[$Index] } function Get-OxyWindowList { [cmdletbinding()] [OutputType([Windows.Window[]])] param() Get-WpfWindowList } ############################################################ function Add-OxyPlotViewInGrid { [cmdletbinding(DefaultParameterSetName="ByDefinition")] [OutputType([OxyPlot.Wpf.PlotView[]])] param( [Parameter(Position=0)] [Windows.Window]$Window, [OxyPlot.PlotModel[]]$PlotModel, [Parameter(ParameterSetName="ByDefinition")] [string[]]$ColumnDefinition = "*", [Parameter(ParameterSetName="ByDefinition")] [string[]]$RowDefinition = "*", [Parameter(ParameterSetName="ByCount")] [int]$Columns = 1, [Parameter(ParameterSetName="ByCount")] [int]$Rows = 1, [bool]$ShowGridLines, [System.Windows.Media.Brush]$Background, [bool]$IsItemsHost, [System.Windows.Style]$Style, [bool]$OverridesDefaultStyle, [bool]$UseLayoutRounding, [System.Windows.ResourceDictionary]$Resources, [System.Object]$DataContext, [System.Windows.Data.BindingGroup]$BindingGroup, [System.Windows.Markup.XmlLanguage]$Language, [string]$Name, [System.Object]$Tag, [System.Windows.Input.InputScope]$InputScope, [System.Windows.Media.Transform]$LayoutTransform, [double]$Width, [double]$MinWidth, [double]$MaxWidth, [double]$Height, [double]$MinHeight, [double]$MaxHeight, [System.Windows.FlowDirection]$FlowDirection, [System.Windows.Thickness]$Margin, [System.Windows.HorizontalAlignment]$HorizontalAlignment, [System.Windows.VerticalAlignment]$VerticalAlignment, [System.Windows.Style]$FocusVisualStyle, [System.Windows.Input.Cursor]$Cursor, [bool]$ForceCursor, [System.Object]$ToolTip, [System.Windows.Controls.ContextMenu]$ContextMenu, [bool]$AllowDrop, [System.Windows.Size]$RenderSize, [System.Windows.Media.Transform]$RenderTransform, [System.Windows.Point]$RenderTransformOrigin, [double]$Opacity, [System.Windows.Media.Brush]$OpacityMask, [System.Windows.Media.Effects.BitmapEffect]$BitmapEffect, [System.Windows.Media.Effects.Effect]$Effect, [System.Windows.Media.Effects.BitmapEffectInput]$BitmapEffectInput, [System.Windows.Media.CacheMode]$CacheMode, [string]$Uid, [System.Windows.Visibility]$Visibility, [bool]$ClipToBounds, [System.Windows.Media.Geometry]$Clip, [bool]$SnapsToDevicePixels, [bool]$IsEnabled, [bool]$IsHitTestVisible, [bool]$Focusable, [bool]$IsManipulationEnabled, [Hashtable]$Options = @{} ) $OptionHash = @{} foreach ($key in $Options.Keys) { $OptionHash.$key = $Options[$key] } if ($PSBoundParameters.ContainsKey('ShowGridLines')) { $OptionHash.ShowGridLines = $ShowGridLines } if ($PSBoundParameters.ContainsKey('Background')) { $OptionHash.Background = $Background } if ($PSBoundParameters.ContainsKey('IsItemsHost')) { $OptionHash.IsItemsHost = $IsItemsHost } if ($PSBoundParameters.ContainsKey('Style')) { $OptionHash.Style = $Style } if ($PSBoundParameters.ContainsKey('OverridesDefaultStyle')) { $OptionHash.OverridesDefaultStyle = $OverridesDefaultStyle } if ($PSBoundParameters.ContainsKey('UseLayoutRounding')) { $OptionHash.UseLayoutRounding = $UseLayoutRounding } if ($PSBoundParameters.ContainsKey('Resources')) { $OptionHash.Resources = $Resources } if ($PSBoundParameters.ContainsKey('DataContext')) { $OptionHash.DataContext = $DataContext } if ($PSBoundParameters.ContainsKey('BindingGroup')) { $OptionHash.BindingGroup = $BindingGroup } if ($PSBoundParameters.ContainsKey('Language')) { $OptionHash.Language = $Language } if ($PSBoundParameters.ContainsKey('Name')) { $OptionHash.Name = $Name } if ($PSBoundParameters.ContainsKey('Tag')) { $OptionHash.Tag = $Tag } if ($PSBoundParameters.ContainsKey('InputScope')) { $OptionHash.InputScope = $InputScope } if ($PSBoundParameters.ContainsKey('LayoutTransform')) { $OptionHash.LayoutTransform = $LayoutTransform } if ($PSBoundParameters.ContainsKey('Width')) { $OptionHash.Width = $Width } if ($PSBoundParameters.ContainsKey('MinWidth')) { $OptionHash.MinWidth = $MinWidth } if ($PSBoundParameters.ContainsKey('MaxWidth')) { $OptionHash.MaxWidth = $MaxWidth } if ($PSBoundParameters.ContainsKey('Height')) { $OptionHash.Height = $Height } if ($PSBoundParameters.ContainsKey('MinHeight')) { $OptionHash.MinHeight = $MinHeight } if ($PSBoundParameters.ContainsKey('MaxHeight')) { $OptionHash.MaxHeight = $MaxHeight } if ($PSBoundParameters.ContainsKey('FlowDirection')) { $OptionHash.FlowDirection = $FlowDirection } if ($PSBoundParameters.ContainsKey('Margin')) { $OptionHash.Margin = $Margin } if ($PSBoundParameters.ContainsKey('HorizontalAlignment')) { $OptionHash.HorizontalAlignment = $HorizontalAlignment } if ($PSBoundParameters.ContainsKey('VerticalAlignment')) { $OptionHash.VerticalAlignment = $VerticalAlignment } if ($PSBoundParameters.ContainsKey('FocusVisualStyle')) { $OptionHash.FocusVisualStyle = $FocusVisualStyle } if ($PSBoundParameters.ContainsKey('Cursor')) { $OptionHash.Cursor = $Cursor } if ($PSBoundParameters.ContainsKey('ForceCursor')) { $OptionHash.ForceCursor = $ForceCursor } if ($PSBoundParameters.ContainsKey('ToolTip')) { $OptionHash.ToolTip = $ToolTip } if ($PSBoundParameters.ContainsKey('ContextMenu')) { $OptionHash.ContextMenu = $ContextMenu } if ($PSBoundParameters.ContainsKey('AllowDrop')) { $OptionHash.AllowDrop = $AllowDrop } if ($PSBoundParameters.ContainsKey('RenderSize')) { $OptionHash.RenderSize = $RenderSize } if ($PSBoundParameters.ContainsKey('RenderTransform')) { $OptionHash.RenderTransform = $RenderTransform } if ($PSBoundParameters.ContainsKey('RenderTransformOrigin')) { $OptionHash.RenderTransformOrigin = $RenderTransformOrigin } if ($PSBoundParameters.ContainsKey('Opacity')) { $OptionHash.Opacity = $Opacity } if ($PSBoundParameters.ContainsKey('OpacityMask')) { $OptionHash.OpacityMask = $OpacityMask } if ($PSBoundParameters.ContainsKey('BitmapEffect')) { $OptionHash.BitmapEffect = $BitmapEffect } if ($PSBoundParameters.ContainsKey('Effect')) { $OptionHash.Effect = $Effect } if ($PSBoundParameters.ContainsKey('BitmapEffectInput')) { $OptionHash.BitmapEffectInput = $BitmapEffectInput } if ($PSBoundParameters.ContainsKey('CacheMode')) { $OptionHash.CacheMode = $CacheMode } if ($PSBoundParameters.ContainsKey('Uid')) { $OptionHash.Uid = $Uid } if ($PSBoundParameters.ContainsKey('Visibility')) { $OptionHash.Visibility = $Visibility } if ($PSBoundParameters.ContainsKey('ClipToBounds')) { $OptionHash.ClipToBounds = $ClipToBounds } if ($PSBoundParameters.ContainsKey('Clip')) { $OptionHash.Clip = $Clip } if ($PSBoundParameters.ContainsKey('SnapsToDevicePixels')) { $OptionHash.SnapsToDevicePixels = $SnapsToDevicePixels } if ($PSBoundParameters.ContainsKey('IsEnabled')) { $OptionHash.IsEnabled = $IsEnabled } if ($PSBoundParameters.ContainsKey('IsHitTestVisible')) { $OptionHash.IsHitTestVisible = $IsHitTestVisible } if ($PSBoundParameters.ContainsKey('Focusable')) { $OptionHash.Focusable = $Focusable } if ($PSBoundParameters.ContainsKey('IsManipulationEnabled')) { $OptionHash.IsManipulationEnabled = $IsManipulationEnabled } if ($PSCmdlet.ParameterSetName -eq "ByCount") { $ColumnDefinition = (1..$Columns) | foreach { "*" } $RowDefinition = (1..$Rows) | foreach { "*" } } $views = New-Object Collections.Generic.List[OxyPlot.Wpf.PlotView] Invoke-WpfWindowAction $Window { $grid = New-Object Windows.Controls.Grid foreach ($key in $OptionHash.Keys) { $grid.$key = $OptionHash[$key] } foreach ($c in $ColumnDefinition) { $def = New-Object Windows.Controls.ColumnDefinition $def.Width = (New-Object Windows.GridLengthConverter).ConvertFromString($c) $grid.ColumnDefinitions.Add($def) } foreach ($r in $RowDefinition) { $def = New-Object Windows.Controls.RowDefinition $def.Height = (New-Object Windows.GridLengthConverter).ConvertFromString($r) $grid.RowDefinitions.Add($def) } $Window.Content = $grid $columnCount = $grid.ColumnDefinitions.Count $rowCount = $grid.RowDefinitions.Count for ($r = 0; $r -lt $rowCount; ++$r) { for ($c = 0; $c -lt $columnCount; ++$c) { $view = New-Object OxyPlot.Wpf.PlotView $views.Add($view) $grid.Children.Add($view) [Windows.Controls.Grid]::SetColumn($view, $c) [Windows.Controls.Grid]::SetRow($view, $r) } } $count = 0 foreach ($m in $PlotModel) { $views[$count].Model = $m ++$count } } $views } function Add-OxyPlotModelToPlotView { [cmdletbinding()] [OutputType([void])] param( [Windows.Window]$Window, [OxyPlot.Wpf.PlotView]$PlotView, [OxyPlot.PlotModel]$PlotModel ) $null = Invoke-WpfWindowAction $Window { $PlotView.Model = $PlotModel } } |