Displaying the UI
The UI can be opened by using the ShowDialog
method of the Window
:
$Window.ShowDialog()
In each of the examples in each of the following sections, the following short function can be used to view the Window
:
function Show-Window {
param (
[Xml]$Xaml
)
Add-Type -AssemblyName PresentationFramework
$Window = [System.Windows.Markup.XamlReader]::Load(
[System.Xml.XmlNodeReader]$Xaml
)
$Window.ShowDialog()
}
Examples and Show-Window
The preceding function is reused in the examples that follow. If it is not present in the PowerShell session, the examples will fail.
The function can be used with the first XAML example:
$xaml = '<?xml version="1.0" encoding="utf-8"?>
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="350" Height="350"...