xs4eyes

Gui-Template

Jul 26th, 2016
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
  2. #from fox deploy.com
  3. $inputXML = @"
  4. <Window x:Class="Azure.Window1"
  5.        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  6.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  7.        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  8.        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  9.        xmlns:local="clr-namespace:Azure"
  10.        mc:Ignorable="d"
  11.  
  12.        Title="iVision Azure Accelerator" Height="524.256" Width="332.076">
  13.    <Grid Margin="0,0,174,0">
  14.    </Grid>
  15. </Window>
  16. "@      
  17.  
  18. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  19.  
  20. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  21. [xml]$XAML = $inputXML
  22. #Read XAML
  23.  
  24.     $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  25.   try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  26. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  27.  
  28. #===========================================================================
  29. # Load XAML Objects In PowerShell
  30. #===========================================================================
  31.  
  32. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  33.  
  34. Function Get-FormVariables{
  35. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  36. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  37. get-variable WPF*
  38. }
  39.  
  40. Get-FormVariables
  41.  
  42. #===========================================================================
  43. # Actually make the objects work
  44. #===========================================================================
  45.  
  46. #Sample entry of how to add data to a field
  47.  
  48. #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  49.  
  50. #===========================================================================
  51. # Shows the form
  52. #===========================================================================
  53. write-host "To show the form, run the following" -ForegroundColor Cyan
  54. '$Form.ShowDialog() | out-null'
  55.  
  56. $Form.ShowDialog() | out-null
Advertisement
Add Comment
Please, Sign In to add comment