We have created some great PowerShell scripts. But as time goes by we have given the scripts to non programmers. So we decided it was time for a simple easy to understand GUI for the PowerShell.
I have watched the channel 9 videos by James Brundage. His videos do a great job of explaining Window, Stack-Panel, Doc-Panel, Grid, Labels, and Textboxes. However there are over 60 controls in total. Not knowing WPF does not help.
What I would like to do is be able to do the following:
Text Input
Dropdown List
RadioButton Group
Checkbox Group
I came up with an example that does the first three but with bugs.
Радиоуправление визуально показывает первую выбранную кнопку, но когда я выбираю значение для группы, оно неверно.
Я не могу найти пример для флажка.
Любые подсказки приветствуются.
Вот это мой тест WPK в PowerShell:
function TestGui {
Import-Module WPK
$SelectedRadio = "First"
New-Window -Title "Test User Input" -WindowStartupLocation CenterScreen `
-Width 400 -Height 300 -Show {
New-Grid -Rows 32*, 32*, 32*, 32* -Columns 100, 1* {
#create style to use on controls
$createLblStyle = @{
Margin = 5
HorizontalAlignment = "right"
VerticalAlignment = "center"
}
#Label Text for this row
New-TextBlock -Text "Pick fruit" `
-Row 0 -Column 0 @createLblStyle
# dropdown ( combo box)
New-ComboBox -Name FruitList `
-row 0 -column 1 @createLblStyle `
-Items { "Apple", "Pear", "Peach" } -SelectedIndex 0
#Label Text for this row
New-TextBlock -Text "Pick number" `
-Row 1 -Column 0 @createLblStyle
# TextBox
New-TextBox -Name TextInputName `
-Row 1 -Column 1 @createLblStyle
#Label Text for this row
New-TextBlock -Text "Get Text Input" `
-Row 2 -Column 0 @createLblStyle
#Do three radio buttons for this row.
New-StackPanel -Row 2 -Column 1 -Orientation Horizontal {
New-RadioButton -Content "Pick first" `
-GroupName Results -IsChecked $True -On_Click {
$SelectedRadio = "First"
}
New-RadioButton -Content "Pick two" `
-GroupName Results -On_Click {
$SelectedRadio = "Second"
}
New-RadioButton -Content "Pick three" `
-GroupName Results -On_Click {
$SelectedRadio = "Third"
}
}
New-Button -Content "_Call PS Script" -Row 3 -Column 0 -Margin 3 -On_Click {
$FruitList = $window | Get-ChildControl FruitList
$TextInputName = $Window | Get-ChildControl TextInputName
$Results = $Window | Get-ChildControl Results
$Window.Close()
write-host "call PS script with: "
write-host "DropDown => " $FruitList.SelectedValue
write-host "TextBox => " $TextInputName.Text
write-host "Radio => " $SelectedRadio
}
New-Button -Content "Cancel" -Row 3 -Column 1 -Margin 3 -On_Click {
$Window.Close()
write-host "Cancel was pressed"
}
}
}
}