Advertisement
Combreal

WPFtoPS-GUI-Template.ps1

May 29th, 2023 (edited)
1,012
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PowerShell 0.66 KB | Source Code | 0 0
  1. <#
  2.     XAML GUI Template
  3. #>
  4.  
  5. Add-Type -AssemblyName PresentationFramework
  6. Add-Type -AssemblyName System.Windows.Forms
  7.  
  8. [xml]$XAML = @"
  9.  
  10. <-- PASTE VISUAL STUDIO XML CODE HERE -->
  11.  
  12. "@
  13. $XAML.Window.RemoveAttribute('x:Class')
  14. $XAML.Window.RemoveAttribute('mc:Ignorable')
  15. $XAMLReader = New-Object System.Xml.XmlNodeReader $XAML
  16. $MainWindow = [Windows.Markup.XamlReader]::Load($XAMLReader)
  17.  
  18. $namenodes = $XAML.SelectNodes("//*[@*[contains(translate(name(.),'n','N'),'Name')]]")
  19. $wpf =@{}
  20. $namenodes | ForEach-Object{$wpf.add($_.Name,$MainWindow.FindName($_.Name))}
  21.  
  22. #$wpf.Button.Add_Click({
  23. #    Write-Host "Hello World"
  24. #})
  25.  
  26. $MainWindow.ShowDialog() | Out-Null
Tags: powershell wpf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement