1

In my listview, when I select on of the item I will show a new view and set the listview to not select any item by set SelectedItem to be null. But the listview still select the old item that I selected. According to this link, I have set

IsSynchronizedWithCurrentItem="True"

But it still same. My item list is compose from the ItemViewModel that inherited from MvxViewModel

Community
  • 1
  • 1

1 Answers1

0

Are you using ListView(ListBox) or any custom control?

A class inherited from MS ListBox (such as ListView) has a static method to unselect all selected items:

ListBox.UnselectAll()

To unselect only one item you can cast selected item to ListBoxItem object and call:

ListBoxItem item = (ListBoxItem)obj;
item.IsSelected = false;

Have you tried it in your code behind? Or you want to achieve this declaratively by XAML markup?

Mikhail Tumashenko
  • 1,683
  • 2
  • 21
  • 28
  • I used ListView. The problem is I change the SelectedItem = null inside the ViewModel but it seem like the ListView does not detect when I set it to null. – user3432518 Sep 08 '15 at 11:02
  • You've got reference to your control in the ViewModel? If so, have you tried ListView.Items.Refresh() after modification of the list? But, if you started using MVVM pattern, you may bind IsSelected property of the ListView to a boolean property of the ViewModel, implementing INotifyPropertyChanged. – Mikhail Tumashenko Sep 08 '15 at 12:01
  • About IsSelected, I tried it and it seems work perfectly unless when I reselect the item that I just selected it does not show a new view as I expected. – user3432518 Sep 08 '15 at 12:09
  • I think the better way is to fix showing a view (ShowViewModel or other feature that you use) – Mikhail Tumashenko Sep 08 '15 at 13:18