Skip to content

Instantly share code, notes, and snippets.

@QuietusPlus
Last active July 29, 2024 03:48
Show Gist options
  • Save QuietusPlus/0bceaf7f52eb23841e3f7bcf191fc6df to your computer and use it in GitHub Desktop.
Save QuietusPlus/0bceaf7f52eb23841e3f7bcf191fc6df to your computer and use it in GitHub Desktop.
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 …
<#
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
@EsherionM
Copy link

Perfect Template but for me only when i remove [@name] in the UI Elements Line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment