SHARE
TWEET

Untitled

a guest Sep 12th, 2017 133 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. $inputXML = @"
  3. <Window x:Class="WpfApp1.MainWindow"
  4.        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  5.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  6.        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7.        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8.        xmlns:local="clr-namespace:WpfApp1"
  9.        mc:Ignorable="d"
  10.        Title="Onboarding Tool" Height="762.272" Width="525">
  11.     <Grid>
  12.         <Image HorizontalAlignment="Left" Height="96" Margin="211,10,0,0" VerticalAlignment="Top" Width="96" Source="C:\Users\lbair\My SecuriSync\IT Department\_Staff Boom\Branding\StaffBoomLogo_96x96.jpg"/>
  13.         <TextBlock HorizontalAlignment="Left" Height="17" Margin="159,106,0,0" TextWrapping="Wrap" Text="StaffBoom Onboarding Tool" VerticalAlignment="Top" Width="202" TextAlignment="Center" FontFamily="Comic Sans MS" RenderTransformOrigin="-0.74,2.361"/>
  14.         <Button Content="OK" HorizontalAlignment="Left" Height="22" Margin="425,561,0,0" VerticalAlignment="Top" Width="63"/>
  15.         <TextBox HorizontalAlignment="Left" Height="23" Margin="99,142,0,0" TextWrapping="Wrap" Text="bacon" VerticalAlignment="Top" Width="96"/>
  16.         <Label Content="User Name" HorizontalAlignment="Left" Height="23" Margin="16,142,0,0" VerticalAlignment="Top" Width="78" RenderTransformOrigin="-0.036,0.554"/>
  17.  
  18.     </Grid>
  19. </Window>
  20. "@      
  21.  
  22. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  23. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  24. [xml]$XAML = $inputXML
  25. #Read XAML
  26.    $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  27.  try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  28. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  29. #===========================================================================
  30. # Load XAML Objects In PowerShell
  31. #===========================================================================
  32. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  33. Function Get-FormVariables{
  34. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  35. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  36. get-variable WPF*
  37. }
  38. Get-FormVariables
  39. #===========================================================================
  40. # Actually make the objects work
  41. #===========================================================================
  42. #Sample entry of how to add data to a field
  43. #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  44. #===========================================================================
  45. # Shows the form
  46. #===========================================================================
  47. write-host "To show the form, run the following" -ForegroundColor Cyan
  48. '$Form.ShowDialog() | out-null'
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top