0
votes

I am trying to get the bool value of the checkbox present in the Listview. I am binding to a bool public property "Assignm" in the view model. I tried the below binding pattern but the problem is if i select one checkbox it selects all checkboxes and vice versa. I think this is because relativesource is listview and it works on complete listview. I also tried changing the relative source to ListviewItem but that didn't trigger anything. Can someone help me please. Do i need to change something here ?

  <GridViewColumn.CellTemplate>
  <DataTemplate>
  <CheckBox  Tag="{Binding MU_Identifier}" IsChecked="{Binding DataContext.Assignm, RelativeSource={RelativeSource FindAncestor, AncestorType=ListView}}">
 </CheckBox>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
2
The Assignm property should be in the item class (where MU_Identifier is). The Binding would be IsChecked="{Binding Assignm}".Clemens
But is it a good idea to add another property to my item class (Entity Model) even though this bool value is not stored in the Database. ? I have web client architecture application. @ClemensSam King
A better practice is to create another model for this purpose, that is this model includes the property needed to be bound. Then create a mapping between the two models.WPInfo

2 Answers

1
votes

Because your binding for IsChecked property is Assignm property which seems to be one property of your view model.

If there is a boolean property named Assignm for the data model of the DataSource of ListView, then just change the binding like this: {Binding Assignm}, as Tag property does.

0
votes

All your items are bounded to a single property, so when one item changes a property in your context it changes on other items.

To provide correct work all your items from ItemsSource should have property IsChecked. Check this Example