View difference between Paste ID: cnYySxs5 and 3P37x5Y5
SHOW: | | - or go back to the newest paste.
1
#ERASE ALL THIS AND PUT XAML BELOW between the @" "@ 
2
$inputXML = @"
3
4-
<Window x:Class="stgmenu.MainWindow"
4+
<Window 
5
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
6
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
7
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
8
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
9
        xmlns:local="clr-namespace:stgmenu"
10
        mc:Ignorable="d"
11
        Title="MainWindow" Height="665.799" Width="799.492">
12
    <Grid>
13
        <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="14,9,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Text="Server"/><LineBreak/><Run/></TextBlock>
14
        <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="13,31,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
15
        <ListView x:Name="listView" HorizontalAlignment="Left" Height="600" Margin="372,14,0,0" VerticalAlignment="Top" Width="410">
16
            <ListView.View>
17
                <GridView>
18
                    <GridViewColumn/>
19
                </GridView>
20
            </ListView.View>
21
        </ListView>
22
        <Button x:Name="button" Content="keepalive" HorizontalAlignment="Left" Margin="20,82,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.42,0.162"/>
23
24
    </Grid>
25
</Window>
26
27
28
"@       
29
 
30
$inputXML = $inputXML -replace 'mc:Ignorable="d"','' -replace "x:N",'N'  -replace '^<Win.*', '<Window'
31
 
32
 
33
[void][System.Reflection.Assembly]::LoadWithPartialName('presentationframework')
34
[xml]$XAML = $inputXML
35
#Read XAML
36
 
37-
    $reader=(New-Object System.Xml.XmlNodeReader $xaml) 
37+
    $reader=(New-Object System.Xml.XmlNodeReader $xaml)
38-
  try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
38+
try{$Form=[Windows.Markup.XamlReader]::Load( $reader )}
39-
catch{Write-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
39+
catch{return $Error[0]}
40
#===========================================================================
41
# Load XAML Objects In PowerShell
42
#===========================================================================
43
 
44
$xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
45
 
46
Function Get-FormVariables{
47
if ($global:ReadmeDisplay -ne $true){Write-host "If you need to reference this display again, run Get-FormVariables" -ForegroundColor Yellow;$global:ReadmeDisplay=$true}
48
write-host "Found the following interactable elements from our form" -ForegroundColor Cyan
49
get-variable WPF*
50
}
51
 
52
Get-FormVariables
53
 
54
#===========================================================================
55
# Actually make the objects work
56
#===========================================================================
57
 
58
 
59
#Sample entry of how to add data to a field
60
 
61
#$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
62
 
63
#===========================================================================
64
# Shows the form
65
#===========================================================================
66
write-host "To show the form, run the following" -ForegroundColor Cyan
67
$Form.ShowDialog() | out-null