Skip to content

Instantly share code, notes, and snippets.

@tonylea
Created April 16, 2016 00:44
Show Gist options
  • Save tonylea/5b35715899534a22c9ea28a12b70fa6f to your computer and use it in GitHub Desktop.
Save tonylea/5b35715899534a22c9ea28a12b70fa6f to your computer and use it in GitHub Desktop.
PowerShell GUI Boilerplate
Function Get-FormVariables {
if ($global:ReadmeDisplay -ne $true) { Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow; $global:ReadmeDisplay = $true }
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
get-variable WPF*
}
# Create WPF C# Form is Visual Studio and copy the XAML data
$inputXML = @"
VISUAL STUDIO XAML GOES HERE
"@
$inputXML = $inputXML -replace 'mc:Ignorable="d"', '' -replace "x:N", 'N' -replace '^<Win.*', '<Window'
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
[xml]$XAML = $inputXML
$reader = (New-Object System.Xml.XmlNodeReader $xaml)
try {
$Form = [Windows.Markup.XamlReader]::Load($reader)
} catch {
Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."
}
$xaml.SelectNodes("//*[@Name]") | ForEach-Object{ Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) }
# Add Form Actions
# Load Form
$Form.ShowDialog() | out-null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment