我们创建了一些很棒的PowerShell脚本。但随着时间的推移,我们已经将脚本交给了非程序员。所以我们决定是时候为PowerShell简单易懂的GUI了。将WPK用于PowerShell GUI
我看过詹姆斯布伦戴奇的9频道录像。他的视频在解释Window,Stack-Panel,Doc-Panel,Grid,Labels和Textboxes方面做得非常出色。 但是总共有60多个控件。不知道WPF没有帮助。
我想什么做的是能够做到以下几点:
文本输入
下拉列表
单选按钮组
复选框组
我想出了,做了一个例子前三名但有bug。
无线电控制器直观地显示了第一个选择的按钮,但是当我拉出该组的值时,它是不正确的。
我找不到复选框的示例。
任何提示将不胜感激。
这是我在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"
}
}
}
}
单选按钮有什么问题?我看不到任何东西。 –
bernd,这是当我试图让选定的按钮回来,它并没有给我一个我选择的。 – Razcer
我测试了所有电子情况的初始状态,中间,右侧,左侧单选按钮和'Call PS Script'给出:Radio => First,Radio => First,Radio => Third,Radio => First。你是否总是获得相同的价值,或者你获得了不同的价值,但是错误的价值观? –