Add-Type -AssemblyName "PresentationCore", "PresentationFramework", "WindowsBase" [xml]$xamlMarkup = @' '@ $xamlGui = [System.Windows.Markup.XamlReader]::Load((New-Object System.Xml.XmlNodeReader $xamlMarkup)) $xamlMarkup.SelectNodes('//*[@Name]') | ForEach-Object { New-Variable -Name $_.Name -Value $xamlGui.FindName($_.Name) } #region Script Functions function Hide-Console { <# .SYNOPSIS Hide Powershell console before show WPF GUI. #> [CmdletBinding()] param () Add-Type -Name Window -Namespace Console -MemberDefinition ' [DllImport("Kernel32.dll")] public static extern IntPtr GetConsoleWindow(); [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr hWnd, Int32 nCmdShow); ' [Console.Window]::ShowWindow([Console.Window]::GetConsoleWindow(), 0) } #endregion #region Controls Events $Window.add_MouseLeftButtonDown( { $Window.DragMove() }) $Window.add_SizeChanged( { if ($Window.ActualWidth -ge 1000) { $PanelToggle.Orientation = "Horizontal" $PlaceholderFirstColumn.Visibility = "Visible" } else { $PanelToggle.Orientation = "Vertical" $PlaceholderFirstColumn.Visibility = "Collapsed" } }) $ButtonTitleMin.add_MouseLeftButtonDown( { $Window.WindowState = "Minimized" }) $ButtonTitleMax.add_MouseLeftButtonDown( { if ($Window.WindowState -eq "Normal") { $Window.WindowState = "Maximized" } else { $Window.WindowState = "Normal" } }) $ButtonTitleClose.add_MouseLeftButtonDown( { $Window.Close() }) #endregion Hide-Console $xamlGui.ShowDialog() | Out-Null