Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
- $inputXML = @"
- <Window x:Name="CAB_Cybersecurity_Application_Barrier" x:Class="TroubleshootingWPF_App.MainWindow"
- xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
- xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
- xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
- xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
- xmlns:local="clr-namespace:TroubleshootingWPF_App"
- mc:Ignorable="d"
- Title="Cybersecurity Application Barrier" Height="450" Width="800">
- <Grid>
- <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"/>
- <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"/>
- <Label Content="Username:" HorizontalAlignment="Left" Margin="227,234,0,0" VerticalAlignment="Top" Width="70"/>
- <TextBox Name="Textbox" HorizontalAlignment="Left" Height="23" Margin="318,238,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Text="TextBox"/>
- <Button Name="Button" Content="Okay" HorizontalAlignment="Left" Margin="337,295,0,0" VerticalAlignment="Top" Width="75"/>
- </Grid>
- </Window>
- "@
- $inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
- [void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
- [xml]$XAML = $inputXML
- #Read XAML
- $reader=(New-Object System.Xml.XmlNodeReader $xaml)
- try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
- catch{Write-Warning "Unable to parse XML, with error: $($Error[0])`n Ensure that there are NO SelectionChanged properties (PowerShell cannot process them)"
- throw}
- #===========================================================================
- # Load XAML Objects In PowerShell
- #===========================================================================
- $xaml.SelectNodes("//*[@Name]") | %{"trying item $($_.Name)";
- try {Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) -ErrorAction Stop}
- catch{throw}
- }
- 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*
- }
- Get-FormVariables
- #===========================================================================
- # Use this space to add code to the various form elements in your GUI
- #===========================================================================
- #Reference
- #Adding items to a dropdown/combo box
- #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
- #Setting the text of a text box to the current PC name
- #$WPFtextBox.Text = $env:COMPUTERNAME
- #Adding code to a button, so that when clicked, it pings a system
- # $WPFbutton.Add_Click({ Test-connection -count 1 -ComputerName $WPFtextBox.Text
- # })
- #===========================================================================
- # Shows the form
- #===========================================================================
- write-host "To show the form, run the following" -ForegroundColor Cyan
- '$Form.ShowDialog() | out-null'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement