Advertisement
Guest User

Untitled

a guest
Jul 2nd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $inputXML = @"
  2. <Window x:Name="CAB_Cybersecurity_Application_Barrier" x:Class="TroubleshootingWPF_App.MainWindow"
  3.        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4.        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5.        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  6.        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  7.        xmlns:local="clr-namespace:TroubleshootingWPF_App"
  8.        mc:Ignorable="d"
  9.        Title="Cybersecurity Application Barrier" Height="450" Width="800">
  10.    <Grid>
  11.        <Image HorizontalAlignment="Left" Height="137" Margin="200,20,0,0" VerticalAlignment="Top" Width="400" Source="C:\Users\cbartho\Documents\General Intern Info\AOI Software\COPlogo.png" Stretch="Fill"/>
  12.        <TextBlock HorizontalAlignment="Left" Margin="227,162,0,0" TextWrapping="Wrap" Text="This application is for early on boarding, and should allow for an increased pace at which the analyst can analyze a multitude of alerts. " VerticalAlignment="Top" Height="67" Width="339" FontFamily="Arial"/>
  13.        <Label Content="Username:" HorizontalAlignment="Left" Margin="227,234,0,0" VerticalAlignment="Top" Width="70"/>
  14.        <TextBox HorizontalAlignment="Left" Height="23" Margin="318,238,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" TextChanged="TextBox_TextChanged" Text="TextBox"/>
  15.        <Button Content="Okay" HorizontalAlignment="Left" Margin="337,295,0,0" VerticalAlignment="Top" Width="75"/>
  16.  
  17.    </Grid>
  18. </Window>
  19.  
  20. "@      
  21.  
  22. $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
  23.  
  24. [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
  25. [xml]$XAML = $inputXML
  26. #Read XAML
  27.  
  28.     $reader=(New-Object System.Xml.XmlNodeReader $xaml)
  29.   try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
  30. catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
  31.  
  32. #===========================================================================
  33. # Load XAML Objects In PowerShell
  34. #===========================================================================
  35.  
  36. $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
  37.  
  38. Function Get-FormVariables{
  39. if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
  40. write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
  41. get-variable WPF*
  42. }
  43.  
  44. Get-FormVariables
  45.  
  46. #===========================================================================
  47. # Actually make the objects work
  48. #===========================================================================
  49.  
  50. #Sample entry of how to add data to a field
  51.  
  52. #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
  53.  
  54. #===========================================================================
  55. # Shows the form
  56. #===========================================================================
  57. write-host "To show the form, run the following" -ForegroundColor Cyan
  58. '$Form.ShowDialog() | out-null'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement