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="SQLAdmin" Height="250" Width="400">
<Grid>
<Menu Height="22" Name="MainMenu" VerticalAlignment="Top" HorizontalAlignment="Stretch">
<MenuItem Header="_Systems" Name="SystemsMenuItem">
<MenuItem Header="_Tools">
<MenuItem Header="Management Studio" Name="MgmtStudMenuItem">
</menuitem>
</menu>
<Canvas Name="ContentCanvas" Margin="0,22,0,0">
</grid>
</window>
'@
$Reader = New-Object System.Xml.XmlNodeReader $XAML
$Form = [Windows.Markup.XamlReader]::Load( $Reader )
$Label = New-Object Windows.Controls.Label
$Label.Content = "This initial laben contain several lines`nof text."
$ContentCanvas = $Form.FindName("ContentCanvas")
$ContentCanvas.Children.Add($Label)
$SystemsMenuItem = $Form.FindName("SystemsMenuItem")
$SystemsMenuItem.add_click({ $Label.Content = 'SQLAdmin' })
$MgmtStudMenuItem = $Form.FindName("MgmtStudMenuItem")
$MgmtStudMenuItem.Add_Click({ $Label.Content = 'Starting SQL Server Management Studio...' })
$Form.ShowDialog() | out-null
The result is similar to that of the former WPF MenuItem example.
No comments:
Post a Comment