Chapters/graphical-controllers-wpf/stack-services.ps1
#WPF Demonstration using a stack panel #add the assembly Add-Type -AssemblyName PresentationFramework #create the form $form = New-Object System.Windows.Window #define what it looks like $form.Title = "Services" $form.Height = 200 $form.Width = 300 #create the stack panel $stack = New-Object System.Windows.Controls.StackPanel #create a label and assign properties $label = New-Object System.Windows.Controls.Label $label.HorizontalAlignment = "Left" $label.Content = "Enter a Computer name:" #add to the stack $stack.AddChild($label) #create a text box and assign properties $TextBox = New-Object System.Windows.Controls.TextBox $TextBox.Width = 115 $TextBox.HorizontalAlignment = "Left" #set a default value $TextBox.Text = $env:COMPUTERNAME #add to the stack $stack.AddChild($TextBox) #create a button and assign properties $btn = New-Object System.Windows.Controls.Button $btn.Content = "_OK" $btn.Width = 75 $btn.VerticalAlignment = "Bottom" $btn.HorizontalAlignment = "Center" #this will sort of work $OK = { Write-Host "Getting services from $($textbox.Text)" -ForegroundColor Green Get-Service -ComputerName $textbox.Text | Where-Object status -eq 'running' } #add an event handler $btn.Add_click($OK) #add to the stack $stack.AddChild($btn) #add the stack to the form $form.AddChild($stack) #show the form $form.ShowDialog() i |