I'm working on a GUI interface for my collegue and I want to add a ListView with checkboxes and "make stuff" when the users are checking the checkbox.
I've done a lot of search on StackOverflow and Technet and so far, I only got some checkbox that I can set (with binding) like I want, but I'm unable to create or capture any event on the check event.
I've made a little GUI interface to do my trial and error. So my XAML code looks like this :
<Window
xmlns="http://ift.tt/o66D3f"
xmlns:x="http://ift.tt/mPTqtT"
xmlns:d="http://ift.tt/pHvyf2"
xmlns:mc="http://ift.tt/pzd6Lm"
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>
And my Powershell code looks like this :
Set-Location $PSScriptRoot
#Loading modules
#Module to import XAML inspire by these nice walkthrough :
- http://ift.tt/2y3PRr2
- http://ift.tt/2ryVMWq
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
The add_MouseLeftButtonUp works great everywhere in the listview, except the checkbox.
I've found a lot of help and solution for C#, but nothing seems to work in Powershell. So any suggestion or help would and will be appreciated.
Thanks!
Aucun commentaire:
Enregistrer un commentaire