1

I have two list views in a scene (listview1 and listview2, contents of listview2 depends on the selecteditem on listview1) and when I navigate to the scene I want the first item in listview1 to be selected and the details be displayed in the other listview (listview2) but I do not want any item in the listView2 selected by default.

What i am observing is that the first item in listView2 is also selected and that is causing selectionchanged event to be triggered for listview2 (which I want to be triggered only if the user explicitly selects it)

gforg
  • 263
  • 1
  • 4
  • 19

3 Answers3

6

No need for workarounds. Just set IsSynchronizedWithCurrentItem="False" in your ListView. This also works for GridViews.

dcastro
  • 66,540
  • 21
  • 145
  • 155
  • This did not work for me in WinRT. (Windows 8.1, .NET 4.5.1.0) What i ended up doing is setting my ListView's SelectionMode to None, and wiring up Tapped events in the item's Data Template. This way the app only handles user interaction, and not what MS thinks should be selected :) – Jack Dec 19 '14 at 23:19
1

selectionchanged events will be triggered and cannot be stopped. But it can be bypassed (using a flag) in the code behind.

If ListView is bound to CollectionViewSource, CollectionViewSource sets the first items as selected.

If ListView is bound to regular Collection, no items will be selected automatically.

Tilak
  • 30,108
  • 19
  • 83
  • 131
  • if I use "collection" I get an error saying collection is not supported in metro style project. So is my solution to not set the selection changed event until after the first load and assignment? – gforg Jul 22 '12 at 19:20
0

This is because you set the event handler of list view 1 & 2 by XAML, maybe. If you set the data source and selected item first, then, set the event handler by your code behind, it works well, I think.

Mamoru Satoh
  • 2,670
  • 23
  • 23