Template: Use PowerShell to launch a .xaml file (MainWindow.xaml) designed within Visual Studio. It automatically removes attributes which are otherwise incompatible, so design in Visual Studio and launch your GUI without any additional steps. The template supports "Windows Presentation Foundation" and "Windows Forms" by default, add additional .NET Framework classes if needed.
<#
PowerShell XAML Template
by QuietusPlus
#>
<#
Include
#>
# .NET Framework classes
Add-Type -AssemblyName PresentationFramework
Add-Type -AssemblyName System.Windows.Forms
# XAML
[xml]$XAML = Get-Content "MainWindow.xaml"
$XAML.Window.RemoveAttribute('x:Class')
$XAML.Window.RemoveAttribute('mc:Ignorable')
$XAMLReader = New-Object System.Xml.XmlNodeReader $XAML
$MainWindow = [Windows.Markup.XamlReader]::Load($XAMLReader)
# UI Elements
$XAML.SelectNodes("//*[@Name]") | %{Set-Variable -Name ($_.Name) -Value $MainWindow.FindName($_.Name)}
<#
Functions
#>
<#
Initialisation
#>
# Show MainWindow
$MainWindow.ShowDialog() | Out-Null