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:

  1. get inside sitescollection being called, (which populates listview , returns collection).
  2. get inside selectedsite called, returns null
  3. 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

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -