WPF (Windows Presentation Foundation) 技術能讓你創建窗口和對話框。它的優勢是在窗體設計時能與代碼分開。
這里有個簡單的顯示彈出消息練習。這個消息是定義在XAML代碼中它的實現類似HTML(但是請區分大小寫)。你能輕松的調整字體大小,內容,顏色等等。不需要嵌入任何代碼。
代碼如下:
$xaml = @"
<Window
xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'>
<Border BorderThickness="20" BorderBrush="Yellow" CornerRadius="9" Background='Red'>
<StackPanel>
<Label FontSize="50" FontFamily='Stencil' Background='Red' Foreground='White' BorderThickness='0'>
System will be rebooted in 15 minutes!
</Label>
<Label HorizontalAlignment="Center" FontSize="15" FontFamily='Consolas' Background='Red' Foreground='White' BorderThickness='0'>
Worried about losing data? Talk to your friendly help desk representative and freely share your concerns!
</Label>
</StackPanel>
</Border>
</Window>
"@
$reader = [System.XML.XMLReader]::Create([System.IO.StringReader] $xaml)
$window = [System.Windows.Markup.XAMLReader]::Load($reader)
$Window.AllowsTransparency = $True
$window.SizeToContent = 'WidthAndHeight'
$window.ResizeMode = 'NoResize'
$Window.Opacity = .7
$window.Topmost = $true
$window.WindowStartupLocation = 'CenterScreen'
$window.WindowStyle = 'None'
# show message for 5 seconds:
$null = $window.Show()
Start-Sleep -Seconds 5
$window.Close()
新聞熱點
疑難解答