Created
April 16, 2016 00:44
-
-
Save tonylea/5b35715899534a22c9ea28a12b70fa6f to your computer and use it in GitHub Desktop.
PowerShell GUI Boilerplate
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
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