View difference between Paste ID: gkR6uCKZ and 2M4tdSCE
SHOW: | | - or go back to the newest paste.
1
    #ERASE ALL THIS AND PUT XAML BELOW between the @" "@ 
2
$inputXML = @"
3
<Window x:Name="CAB_Cybersecurity_Application_Barrier" x:Class="TroubleshootingWPF_App.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:TroubleshootingWPF_App"
9
        mc:Ignorable="d"
10
        Title="Cybersecurity Application Barrier" Height="450" Width="800">
11
    <Grid>
12
        <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"/>
13
        <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"/>
14-
        <TextBox HorizontalAlignment="Left" Height="23" Margin="318,238,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" TextChanged="TextBox_TextChanged" Text="TextBox"/>
14+
15-
        <Button Content="Okay" HorizontalAlignment="Left" Margin="337,295,0,0" VerticalAlignment="Top" Width="75"/>
15+
        <TextBox Name="Textbox" HorizontalAlignment="Left" Height="23" Margin="318,238,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Text="TextBox"/>
16
        <Button Name="Button" Content="Okay" HorizontalAlignment="Left" Margin="337,295,0,0" VerticalAlignment="Top" Width="75"/>
17
18
    </Grid>
19
</Window>
20-
"@      
20+
21
"@ 
22-
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
22+
 
23
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N' -replace '^<Win.*', '<Window'
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 )}
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."}
30+
catch{Write-Warning "Unable to parse XML, with error: $($Error[0])`n Ensure that there are NO SelectionChanged properties (PowerShell cannot process them)"
31
    throw}
32
 
33
#===========================================================================
34
# Load XAML Objects In PowerShell
35
#===========================================================================
36-
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
36+
37
$xaml.SelectNodes("//*[@Name]") | %{"trying item $($_.Name)";
38
    try {Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name) -ErrorAction Stop}
39
    catch{throw}
40
    }
41
 
42
Function Get-FormVariables{
43
if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
44
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
45
get-variable WPF*
46
}
47-
# Actually make the objects work
47+
 
48
Get-FormVariables
49
 
50-
#Sample entry of how to add data to a field
50+
51
    # Use this space to add code to the various form elements in your GUI
52-
#$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
52+
    #===========================================================================
53
                                                                    
54
     
55-
# Shows the form
55+
    #Reference 
56
 
57
    #Adding items to a dropdown/combo box
58
      #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
59
     
60
    #Setting the text of a text box to the current PC name    
61
      #$WPFtextBox.Text = $env:COMPUTERNAME
62
     
63
    #Adding code to a button, so that when clicked, it pings a system
64
    # $WPFbutton.Add_Click({ Test-connection -count 1 -ComputerName $WPFtextBox.Text
65
    # })
66
    #===========================================================================
67
    # Shows the form
68
    #===========================================================================
69
write-host "To show the form, run the following" -ForegroundColor Cyan
70
'$Form.ShowDialog() | out-null'