View difference between Paste ID: JBMtSt8S and Pqii5txQ
SHOW: | | - or go back to the newest paste.
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"/>
12+
        <Image Name="Image01" 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"/>
13+
        <TextBlock Name="Text01" 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"/>
14+
        <Button Name="OKButton" 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"/>
15+
        <TextBox Name="Text02" 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"/>
16+
        <Label Name="label01" 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
 
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'