how to disable the default selection in listview w

2019-06-07 02:54发布

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)

3条回答
迷人小祖宗
2楼-- · 2019-06-07 03:15

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

查看更多
何必那么认真
3楼-- · 2019-06-07 03:15

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.

查看更多
对你真心纯属浪费
4楼-- · 2019-06-07 03:18

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.

查看更多
登录 后发表回答