0
votes

I have a listview in xamarin forms, with the itemsource being an array of strings. I also have a cell template that has a binding to that string, and a checkmark that is set to invisible. When an item is selected, I want the cell displaying that item's checkmark to become visible. What is the best way to approach this? It seems that the item selection handler only handles the underlying data, and not the cell itself

1

1 Answers

4
votes

Instead of binding directly to a List<string>, create a ViewModel that contains a string and a bool. Then bind your ListView to a List<MyViewModel>, and bind the IsVisible property of the checkmark to the bool property of the VM. When an item is selected, set the bool property to true in order to show the checkmark.

It's a bit of PITA, but the only way to do it that I'm aware of with the current state of the ListView control. And in the long run using a ViewModel is a good practice to get into.

A slightly more hackish way to do it would be to use a Dictionary<string,bool> instead of a custom ViewModel.