30 lines
805 B
PowerShell
30 lines
805 B
PowerShell
cls
|
|
Add-Type -AssemblyName PresentationFramework
|
|
Add-Type -AssemblyName System
|
|
|
|
if (test-path -Path "D:\PS_WPF_Sample.xaml"){
|
|
[XML]$XAML = Get-Content D:\PS_WPF_Sample.xaml
|
|
}
|
|
|
|
$XAML.Window.RemoveAttribute("x:Class")
|
|
$Reader = New-Object System.Xml.XmlNodeReader $XAML
|
|
$Form = [Windows.Markup.XamlReader]::Load($Reader)
|
|
|
|
$btnOKClick = {$PSLabel.Content = $PSText.Text}
|
|
|
|
$btnExitClick = {$Form.Close()}
|
|
|
|
Function GenerateForm {
|
|
#create objects from controls
|
|
$PSText = $Form.FindName('PSText')
|
|
$PSLabel = $Form.FindName('PSLabel')
|
|
$PSBtnOK = $Form.FindName('PSBtnOK')
|
|
$PSBtnExit = $Form.FindName('PSBtnExit')
|
|
|
|
#Add the events to the controls
|
|
$PSBtnOK.Add_Click($btnOKClick)
|
|
$PSBtnExit.Add_Click($btnExitClick)
|
|
|
|
$Form.ShowDialog()| Out-Null
|
|
}
|
|
GenerateForm |