Last active
July 29, 2024 03:48
-
-
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 …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Perfect Template but for me only when i remove [@name] in the UI Elements Line.