Last active
November 4, 2022 11:03
-
-
Save FooBartn/dd62af73ed5703f121ea5688243009cb to your computer and use it in GitHub Desktop.
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
# Note: Edited from | |
# https://foxdeploy.com/resources/ise-snippets/xaml-to-gui/ original XAML loader script | |
# Change contents of here string to your XAML code from Visual Studio | |
$RawXAML = @" | |
Enter XAML contents here | |
"@ | |
[void][System.Reflection.Assembly]::LoadWithPartialName('PresentationFramework') | |
[xml]$XAML = $RawXAML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window' | |
#Read XAML | |
$XAMLReader= New-Object System.Xml.XmlNodeReader $XAML | |
try{ | |
$Form=[Windows.Markup.XamlReader]::Load($XAMLReader) | |
} catch { | |
Throw "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed." | |
} | |
#=========================================================================== | |
# Load XAML Objects In PowerShell | |
#=========================================================================== | |
$XAML.SelectNodes("//*[@Name]") | | |
ForEach-Object { | |
Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) | |
} | |
Get-Variable WPF* # Will show you the form variables | |
#=========================================================================== | |
# Events | |
#=========================================================================== | |
#=========================================================================== | |
# Shows the form | |
#=========================================================================== | |
$Form.ShowDialog() | Out-Null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment