8
0
Skriptentwickung/test/PS_WPF_Sample.ps1
2024-01-24 16:42:38 +01:00

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