ListView with CheckBox
Hi,
Anyone having a way to retrieve the listview raw at the moment you check a checkbox ?
When you check the CheckBox, the listview row is not selected (I tried all SelectionModes) so no way to get the SelectedItem or SelectedIndex.
I'm running out of ideas... :p
I have the following XAML code:
Anyone having a way to retrieve the listview raw at the moment you check a checkbox ?
When you check the CheckBox, the listview row is not selected (I tried all SelectionModes) so no way to get the SelectedItem or SelectedIndex.
I'm running out of ideas... :p
I have the following XAML code:
Code: Select all
<ListView x:Name="itListViewFiles" SelectionMode="Single">
<ListView.View>
<GridView>
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="{x:Type GridViewColumnHeader}">
<Setter Property="Visibility" Value="Hidden"/>
</Style>
</GridView.ColumnHeaderContainerStyle>
<GridViewColumn Header="">
<GridViewColumn.CellTemplate>
<DataTemplate>
<CheckBox Margin="0" VerticalAlignment="Center" IsChecked="{Binding IsChecked}" Checked="OnCheck"></CheckBox>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
<GridViewColumn Header="{StaticResource locRevitFileName}">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="0" Text="{Binding Text}"></TextBlock>
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
</ListView>
Re: ListView with CheckBox
Still no solution to this problem.
In the mean time (and if someone's got the same problem) I've done the following:
My listview items are : public class CheckBoxListViewItem : INotifyPropertyChanged
I just added an ugly static to the class (public static CheckBoxListViewItem m_LastItemChanged = null;) Which is updated on RaisePropertyChanged...
In the mean time (and if someone's got the same problem) I've done the following:
My listview items are : public class CheckBoxListViewItem : INotifyPropertyChanged
I just added an ugly static to the class (public static CheckBoxListViewItem m_LastItemChanged = null;) Which is updated on RaisePropertyChanged...
-
-
sfernandez
Site Admin
- Posts: 2057
- Joined:
Re: ListView with CheckBox
Have you tried to search up the tree (using VisualTreeHelper.GetParent) looking for the ListViewItem?
You will receive the CheckBox being clicked on the OnCheck event handler.
Anyway, I think taking an MVVM approach to this will simplify things. You could bind a property of your viewmodel to the CheckBox.IsChecked, when the setter gets triggered do the required logic, and update other properties that will be bound to the ListViewItem to reflect the change.
Do you think any of this could work in your scenario?
You will receive the CheckBox being clicked on the OnCheck event handler.
Anyway, I think taking an MVVM approach to this will simplify things. You could bind a property of your viewmodel to the CheckBox.IsChecked, when the setter gets triggered do the required logic, and update other properties that will be bound to the ListViewItem to reflect the change.
Do you think any of this could work in your scenario?
Re: ListView with CheckBox
Didn't try this as I usualy avoid using VisualTreeHelper on List. I remember cases where with DatagridView VisualTreeHelper wasn't of any help due to virtualisation of items (to manage large list of items).Have you tried to search up the tree (using VisualTreeHelper.GetParent) looking for the ListViewItem?
You will receive the CheckBox being clicked on the OnCheck event handler.
That's what I've done in the end, but I was pointing out the difference with wpf where the click on the checkbox trigger the selection of the row. Therefore you only have to get the SelectedItem (otherwise you only have access to the sender wich is the CheckBox...)Anyway, I think taking an MVVM approach to this will simplify things. You could bind a property of your viewmodel to the CheckBox.IsChecked, when the setter gets triggered do the required logic, and update other properties that will be bound to the ListViewItem to reflect the change.
I've seen another difference with wpf. While trying to remove the GridViewColumnHeader of the list view. It works in Blend but not in Noesis Unity.
I tried :
<GridView.ColumnHeaderContainerStyle>
<Style TargetType="GridViewColumnHeader">
<Setter Property="Visibility" Value="Hidden"/>
</Style>
</GridView.ColumnHeaderContainerStyle>
but also : <Setter Property="Visibility" Value="Collapsed"/>
and even : <Setter Property="Height" Value="0"/>
With no success.
Who is online
Users browsing this forum: Bing [Bot] and 0 guests