c# - Expander View connected with NotifyCollectionChangedAction randomly expands items -
in windows phone 8 application i've created observable collection noticing when item changes in collection. here collection code:
public class trulyobservablecollection<t> : observablecollection<t> t : inotifypropertychanged { public trulyobservablecollection() : base() { collectionchanged += new notifycollectionchangedeventhandler(trulyobservablecollection_collectionchanged); } void trulyobservablecollection_collectionchanged(object sender, notifycollectionchangedeventargs e) { if (e.newitems != null) { foreach (object item in e.newitems) { var test = item inotifypropertychanged; (item inotifypropertychanged).propertychanged += new propertychangedeventhandler(item_propertychanged); } } if (e.olditems != null) { foreach (object item in e.olditems) { (item inotifypropertychanged).propertychanged -= new propertychangedeventhandler(item_propertychanged); } } } void item_propertychanged(object sender, propertychangedeventargs e) { notifycollectionchangedeventargs = new notifycollectionchangedeventargs(notifycollectionchangedaction.reset); oncollectionchanged(a); } }
the situation im going describe happens both controls: expander view (silverlight toolkit) , expander control (telerik controls). in view have list of expander views/controls. on item tap event change in tapped item , refresh list. here code how i'm doing it:
viewmodel:
public trulyobservablecollection<symbolrecord> symbols {get; set;} private relaycommand<symbolrecord> tapcommand; public relaycommand<symbolrecord> tapcommand { { return tapcommand ?? (tapcommand = new relaycommand<symbolrecord>((item) => { item.symbol = "test"; })); } }
view:
<telerikdata:radjumplist x:name="listcontrol" grid.row="1"ischeckmodeenabled="false" grouppickeritemtemplate="{staticresource jumplistheaderitemtemplate}" groupheadertemplate="{staticresource jumplistheadertemplate}" itemssource="{binding path=symbols}" > <telerikdata:radjumplist.itemtemplate> <datatemplate> <stackpanel> <toolkit:expanderview itemssource="{binding}" expander="{binding}" verticalalignment="stretch" verticalcontentalignment="stretch" expandertemplate="{staticresource expandercontrolcontenttemplate}" > <toolkit:expanderview.items> <textbox text="test"></textbox></toolkit:expanderview.items> </toolkit:expanderview> </stackpanel> </datatemplate> </telerikdata:radjumplist.itemtemplate> </telerikdata:radjumplist> <i:interaction.triggers> <i:eventtrigger eventname="itemtap" sourcename="listcontrol" > <cmd:eventtocommand command="{binding tapcommand}" commandparameter="{binding selecteditem, elementname=listcontrol}" /> </i:eventtrigger> </i:interaction.triggers>
when click on item in emulator property symbol changing what's more random items being expanded. dont know why happening. please me
what mean refreshing list?
do want put new data int it? if there's no need use trulyobser... nor call collectionchanged @ all. use methods remove, add, insert etc.
item template automatically get's datacontext proper collection element. , binding works normal. simple inotifycollectionchanged enough.
if want expand expander in view's code-behind. if code-behind want avoid create property isexpanded in vm , bind expander's isexpanded property.
you can set your's vm isexpanded property using trulyobservablecollection. when 1 of item's in collection changed set it's isexpanded true.
anyways. in cases there's no need "trulyobservablecollection"
Comments
Post a Comment