Skip to content

Instantly share code, notes, and snippets.

@sunnyone
Created June 11, 2012 04:53
Show Gist options
  • Save sunnyone/2908566 to your computer and use it in GitHub Desktop.
Save sunnyone/2908566 to your computer and use it in GitHub Desktop.
PowerShell XAML Example
Add-Type -AssemblyName presentationframework
[xml]$XAML = @'
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="100" Width="20">
<StackPanel>
<TextBox Name="textWeather" />
<Button Name="buttonGet" Content="Get"/>
</StackPanel>
</Window>
'@
$reader=(New-Object System.Xml.XmlNodeReader $xaml)
$window=[Windows.Markup.XamlReader]::Load( $reader )
$textbox = $window.FindName("textWeather")
$button = $window.FindName("buttonGet")
$button_clicked = $button.add_Click
$button_clicked.Invoke({
$proxy = New-WebServiceProxy -Uri http://www.webservicex.com/globalweather.asmx?WSDL
$textbox.Text = ([xml]$proxy.GetWeather('Tokyo', 'Japan')).CurrentWeather.SkyConditions
})
$window.ShowDialog() | out-null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment