我正在为我的同事开发一个GUI界面,我想在用户选中复选框时添加一个带复选框的ListView和“make stuff”。
我在StackOverflow和Technet上做了很多搜索,到目前为止,我只有一些我可以设置(带有绑定)的复选框,但是我无法在支票上创建或捕获任何事件事件
我做了一个小的GUI界面来进行试验和错误。所以我的XAML代码如下所示:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GUI_Techgenix"
mc:Ignorable="d"
Title="Powershell GUI Training" Height="250" Width="400">
<Grid>
<ListView x:Name="listSort" HorizontalAlignment="Left" Height="132" Margin="15,15,0,0" VerticalAlignment="Top" Width="350">
<ListView.View>
<GridView AllowsColumnReorder="true" ColumnHeaderToolTip="InfoPaquet">
<GridViewColumn Header="Play">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox IsChecked="{Binding Play}"/>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=PkgName}">
<GridViewColumnHeader>Package Name</GridViewColumnHeader>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=ProgramName}">
<GridViewColumnHeader>Program Name</GridViewColumnHeader>
</GridViewColumn>
<GridViewColumn DisplayMemberBinding="{Binding Path=SequenceID}">
<GridViewColumnHeader>SequenceID</GridViewColumnHeader>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
</Grid>
</Window>
我的Powershell代码如下所示:
Set-Location $PSScriptRoot
#Loading modules
#Module to import XAML inspire by these nice walkthrough :
- https://foxdeploy.com/2015/04/16/part-ii-deploying-powershell-guis-in-minutes-using-visual-studio/
- http://techgenix.com/building-powershell-gui-part2/
Import-Module .\XAML-Loader -ErrorAction Stop
$mainWindow = Open-XamlForm(".\FormTest.xaml")
$testobj = New-Object -TypeName PSObject
$testobj | Add-Member -MemberType NoteProperty -Name ("PkgName") -Value "Test"
$testobj | Add-Member -MemberType NoteProperty -Name ("ProgramName") -Value "Install"
$testobj | Add-Member -MemberType NoteProperty -Name ("Play") -Value "True"
$mainWindow.listSort.AddChild($testobj)
$testobj2 = New-Object -TypeName PSObject
$testobj2 | Add-Member -MemberType NoteProperty -Name ("PkgName") -Value "Test2"
$testobj2 | Add-Member -MemberType NoteProperty -Name ("ProgramName") -Value "Install Notes"
$testobj2 | Add-Member -MemberType NoteProperty -Name ("Play") -Value "False"
$mainWindow.listSort.AddChild($testobj2)
$mainWindow.listSort.add_MouseLeftButtonUp({
Write-host "ClickThatUp!"
})
$mainWindow.XamGUI.ShowDialog() | Out-Null
add_MouseLeftButtonUp
在列表视图中的任何位置都很有用,除了复选框。
答案 0 :(得分:0)
如果您真的想要XAML UI,则此答案不适用。就个人而言,我从不尝试在PowerShell中编写GUI ...
您考虑过Out-GridView吗?
$data = @(
[PSCustomObject]@{Name='Name1'; Description='Description1'}
[PSCustomObject]@{Name='Name2'; Description='Description2'}
[PSCustomObject]@{Name='Name3'; Description='Description3'}
)
$data | Out-GridView -Title MyTitle -OutputMode Multiple