Reputation: 3341
I've got a cross-platform Xamarin Forms application (Android and iOS) that contains a ListView. I would like to have a button displayed in whichever row happens to be the selected row.
I tried defining a button in each row, adding a "Selected" property to my data item, and then specifying
<Button Text=">" IsVisible="{Binding Selected}"/>
and then setting the "Selected" property to true when the row is selected (as is suggested in the Xamarin Forums) but the button never becomes visible except for the row that was initially selected. This isn't surprising, I'm sure the ListView doesn't continually poll my data items, looking for changes.
How can I do this?
Upvotes: 1
Views: 2122
Reputation: 664
Set datasource of the ListView be an obeservableCollection of ViewModels instead of data models. Each of the custom view cell binds to one viewmodel which implements INotifyPropertyChanged. One can alter the selected in the Viewmodel.
Upvotes: 1