Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #ERASE ALL THIS AND PUT XAML BELOW between the @" "@
  2. $inputXML = @"
  3. <Window x:Class="WpfApplication2.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:WpfApplication2"
  9.        mc:Ignorable="d"
  10.        Title="Add-KayakoUser" Height="316.794" Width="656.637" Topmost="True" ShowInTaskbar="False">
  11.    <Grid Margin="0,0,2,-45">
  12.        <Button x:Name="button" Content="Organization ID's" HorizontalAlignment="Left" Height="35" Margin="378,129,0,0" VerticalAlignment="Top" Width="147" FontSize="18.667"/>
  13.        <TextBox x:Name="textBox" HorizontalAlignment="Left" Height="35" Margin="190,129,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="168" FontSize="16"/>
  14.        <Label x:Name="label" Content="Account" HorizontalAlignment="Left" Height="37" Margin="22,127,0,0" VerticalAlignment="Top" Width="148" FontSize="16"/>
  15.        <Label x:Name="label1" Content="Label that has to change content" HorizontalAlignment="Left" Margin="22,186,0,0" VerticalAlignment="Top" Width="162"/>
  16.        <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"/>
  17.    </Grid>
  18. </Window>
  19.  
  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. # Store Form 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. $WPFbutton.Add_Click({
  50.  
  51.     $WPFlabel1.Content = " "    
  52.    $WPFlabel1."Getting data from AD..."
  53.    $WPFlabel1.Refresh()
  54.    Write-host "Updating Window"
  55.    sleep 3
  56.    $WPFlabel1.Content = "Succes, show results, lets go!"
  57.    $WPFlabel1.Refresh()
  58.    Write-host "Updating Window 2"
  59.    
  60. })
  61.  
  62. $Form.ShowDialog() | out-null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement