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:Class="WpfApplication2.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:WpfApplication2"
- mc:Ignorable="d"
- Title="Add-KayakoUser" Height="316.794" Width="656.637" Topmost="True" ShowInTaskbar="False">
- <Grid Margin="0,0,2,-45">
- <Button x:Name="button" Content="Organization ID's" HorizontalAlignment="Left" Height="35" Margin="378,129,0,0" VerticalAlignment="Top" Width="147" FontSize="18.667"/>
- <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="35" Margin="190,129,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="168" FontSize="16"/>
- <Label x:Name="label" Content="Account" HorizontalAlignment="Left" Height="37" Margin="22,127,0,0" VerticalAlignment="Top" Width="148" FontSize="16"/>
- <Label x:Name="label1" Content="Label that has to change content" HorizontalAlignment="Left" Margin="22,186,0,0" VerticalAlignment="Top" Width="162"/>
- <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="22,10,0,0" TextWrapping="Wrap" Text="Created this just for testing purposes. One button that has to updae a label twice with 3 seconds in between" VerticalAlignment="Top" Height="112" Width="307"/>
- </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-Host "Unable to load Windows.Markup.XamlReader. Double-check syntax and ensure .net is installed."}
- #===========================================================================
- # Store Form 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
- #===========================================================================
- $WPFbutton.Add_Click({
- $WPFlabel1.Content = " "
- $WPFlabel1."Getting data from AD..."
- $WPFlabel1.Refresh()
- Write-host "Updating Window"
- sleep 3
- $WPFlabel1.Content = "Succes, show results, lets go!"
- $WPFlabel1.Refresh()
- Write-host "Updating Window 2"
- })
- $Form.ShowDialog() | out-null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement