1
votes

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?

1
you can add some code in the question, I need to watch the code.Marcos José Pérez Pérez
If you're properly updating selected item, and its notifying its changes, what you have will be fine. developer.xamarin.com/guides/xamarin-forms/xaml/xaml-basics/…Taekahn
@Taekahn: The answer to this question was not clearly stated...the link helped. And to clarify, the answer: The listview datasource should implement INotifyPropertyChanged. Not all properties of the listview datasource need to raise the change notification, but at least the "Selected" property (or whichever bool) in the above question should raise the "PropertyChanged".zinczinc

1 Answers

1
votes

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.