OxyWindow.ps1
Set-StrictMode -Version 3 function New-OxyWindow { [cmdletbinding()] [OutputType([Windows.Window])] param( [System.Windows.Shell.TaskbarItemInfo]$TaskbarItemInfo, [System.Boolean]$AllowsTransparency, [System.String]$Title, [System.Windows.Media.ImageSource]$Icon, [System.Windows.SizeToContent]$SizeToContent, [object]$Top, [object]$Left, [System.Windows.WindowStartupLocation]$WindowStartupLocation, [System.Boolean]$ShowInTaskbar, [System.Windows.Window]$Owner, [System.Nullable`1[[System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]]$DialogResult, [System.Windows.WindowStyle]$WindowStyle, [System.Windows.WindowState]$WindowState, [System.Windows.ResizeMode]$ResizeMode, [System.Boolean]$Topmost, [System.Boolean]$ShowActivated, [System.Object]$Content, [System.Windows.DataTemplate]$ContentTemplate, [System.Windows.Controls.DataTemplateSelector]$ContentTemplateSelector, [System.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, [object]$FontSize, [System.Windows.FontStretch]$FontStretch, [System.Windows.FontStyle]$FontStyle, [System.Windows.FontWeight]$FontWeight, [System.Windows.HorizontalAlignment]$HorizontalContentAlignment, [System.Windows.VerticalAlignment]$VerticalContentAlignment, [System.Int32]$TabIndex, [System.Boolean]$IsTabStop, [System.Windows.Thickness]$Padding, [System.Windows.Controls.ControlTemplate]$Template, [System.Windows.Style]$Style, [System.Boolean]$OverridesDefaultStyle, [System.Boolean]$UseLayoutRounding, [System.Windows.ResourceDictionary]$Resources, [System.Object]$DataContext, [System.Windows.Data.BindingGroup]$BindingGroup, [System.Windows.Markup.XmlLanguage]$Language, [System.String]$Name, [System.Object]$Tag, [System.Windows.Input.InputScope]$InputScope, [System.Windows.Media.Transform]$LayoutTransform, [object]$Width, [object]$MinWidth, [object]$MaxWidth, [object]$Height, [object]$MinHeight, [object]$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, [System.Boolean]$ForceCursor, [System.Object]$ToolTip, [System.Windows.Controls.ContextMenu]$ContextMenu, [System.Boolean]$AllowDrop, [System.Windows.Size]$RenderSize, [System.Windows.Media.Transform]$RenderTransform, [System.Windows.Point]$RenderTransformOrigin, [object]$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, [System.String]$Uid, [System.Windows.Visibility]$Visibility, [System.Boolean]$ClipToBounds, [System.Windows.Media.Geometry]$Clip, [System.Boolean]$SnapsToDevicePixels, [System.Boolean]$IsEnabled, [System.Boolean]$IsHitTestVisible, [System.Boolean]$Focusable, [System.Boolean]$IsManipulationEnabled, [Hashtable]$Options = @{} ) $OptionHash = @{ Title = "OxyPlot CLI" } $props = $PROPERTY_HASH["System.Windows.Window"] Assign-ParametersToProperties $props $PSBoundParameters $Options $OptionHash 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, [System.Boolean]$ShowGridLines, [System.Windows.Media.Brush]$Background, [System.Boolean]$IsItemsHost, [System.Windows.Style]$Style, [System.Boolean]$OverridesDefaultStyle, [System.Boolean]$UseLayoutRounding, [System.Windows.ResourceDictionary]$Resources, [System.Object]$DataContext, [System.Windows.Data.BindingGroup]$BindingGroup, [System.Windows.Markup.XmlLanguage]$Language, [System.String]$Name, [System.Object]$Tag, [System.Windows.Input.InputScope]$InputScope, [System.Windows.Media.Transform]$LayoutTransform, [object]$Width, [object]$MinWidth, [object]$MaxWidth, [object]$Height, [object]$MinHeight, [object]$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, [System.Boolean]$ForceCursor, [System.Object]$ToolTip, [System.Windows.Controls.ContextMenu]$ContextMenu, [System.Boolean]$AllowDrop, [System.Windows.Size]$RenderSize, [System.Windows.Media.Transform]$RenderTransform, [System.Windows.Point]$RenderTransformOrigin, [object]$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, [System.String]$Uid, [System.Windows.Visibility]$Visibility, [System.Boolean]$ClipToBounds, [System.Windows.Media.Geometry]$Clip, [System.Boolean]$SnapsToDevicePixels, [System.Boolean]$IsEnabled, [System.Boolean]$IsHitTestVisible, [System.Boolean]$Focusable, [System.Boolean]$IsManipulationEnabled, [Hashtable]$Options = @{} ) $OptionHash = @{} $props = $PROPERTY_HASH["System.Windows.Controls.Grid"] Assign-ParametersToProperties $props $PSBoundParameters $Options $OptionHash 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 } } |