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)
No need for workarounds. Just set
IsSynchronizedWithCurrentItem="False"
in your ListView. This also works for GridViews.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.
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 toCollectionViewSource
,CollectionViewSource
sets the first items as selected.If ListView is bound to regular
Collection
, no items will be selected automatically.