c# - Item is being selected in ListView on page load -
i have listview
in xaml, , it's itemssource , selecteditem property binded viewmodel.
xaml
<listview itemssource="{binding sitescollection}" selecteditem="{binding selectedsite, mode=twoway}"> <listview.itemtemplate> <datatemplate> <textblock text="{binding url}"></textblock> </datatemplate> </listview.itemtemplate> </listview>
viewmodel
public observablecollection<awrestrictedsite> _sitescollection; public observablecollection<awrestrictedsite> sitescollection { { //populate collection return _sitescollection; } } public awrestrictedsite _selectedsite; public awrestrictedsite selectedsite { { return _selectedsite; } set { _selectedsite = value; //do stuff } }
for reason when page loads, selects first item in listview. here happens when page loads:
- get inside sitescollection being called, (which populates listview , returns collection).
- get inside selectedsite called, returns null
- set inside selectedsite called sets value first item
does know why happening?
its 2 way bind, , when loaded, listview
(i think) selects first item in bound collection. try adding loaded
method listview
, setting selecteditem
in there. should happen after first item selected.
Comments
Post a Comment