Chapters/graphical-controllers-wpf/HelloWorld.ps1

#Requires -version 5.0

#create a window form
$form = New-Object System.Windows.Window

#define what it looks like
$form.Title = "Hello WPF"
$form.Height = 200
$form.Width = 300

#create a button
$btn = New-Object System.Windows.Controls.Button
$btn.Content = "_OK"

#define what it looks like
$btn.Width = 65
$btn.HorizontalAlignment = "Center"
$btn.VerticalAlignment = "Center"

#add an event handler
$btn.Add_click({
 $msg = "Hello, World and $env:username!"
 #Write-Host $msg -ForegroundColor Green
 
 #alternate command to test
 Write-Output $msg
})

#add the button to the form
$form.AddChild($btn)

#show the form
$form.ShowDialog() | Out-Null