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
- 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:stgmenu"
- mc:Ignorable="d"
- Title="MainWindow" Height="665.799" Width="799.492">
- <Grid>
- <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="14,9,0,0" TextWrapping="Wrap" VerticalAlignment="Top"><Run Text="Server"/><LineBreak/><Run/></TextBlock>
- <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="13,31,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
- <ListView x:Name="listView" HorizontalAlignment="Left" Height="600" Margin="372,14,0,0" VerticalAlignment="Top" Width="410">
- <ListView.View>
- <GridView>
- <GridViewColumn/>
- </GridView>
- </ListView.View>
- </ListView>
- <Button x:Name="button" Content="keepalive" HorizontalAlignment="Left" Margin="20,82,0,0" VerticalAlignment="Top" Width="75" RenderTransformOrigin="0.42,0.162"/>
- </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{return $Error[0]}
- #===========================================================================
- # Load XAML Objects In PowerShell
- #===========================================================================
- $xaml.SelectNodes("//*[@Name]") | %{Set-Variable -Name "WPF$($_.Name)" -Value $Form.FindName($_.Name)}
- 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
- #===========================================================================
- # Actually make the objects work
- #===========================================================================
- #Sample entry of how to add data to a field
- #$vmpicklistView.items.Add([pscustomobject]@{'VMName'=($_).Name;Status=$_.Status;Other="Yes"})
- #===========================================================================
- # 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