how to disable the default selection in listview when you navigate to it

半腔热情 提交于 2019-12-08 07:20:47

问题


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)


回答1:


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




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/11388768/how-to-disable-the-default-selection-in-listview-when-you-navigate-to-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!