xaml - CheckBox Checked and Unchecked Event fires when scrolling a Listbox in windows phone 8 app? -


i developing windows phone 8 app in using checkbox inside listbox along textblocks.

<listbox x:name="lststudentselect"  itemcontainerstyle="{staticresource listboxitemstyle1}" background="transparent" scrollviewer.verticalscrollbarvisibility="visible" height="487" borderthickness="0"  verticalalignment="top" margin="8,198,10,0">                 <listbox.itemtemplate>                     <datatemplate>                         <stackpanel   orientation="horizontal">                             <stackpanel width="360" orientation="horizontal" horizontalalignment="left">                                 <textblock text="{binding stunum}" width="80"   foreground="black"  textwrapping="wrap"  fontsize="20" verticalalignment="center" />                                 <textblock  text="{binding name}" width="280"  foreground="black"  textwrapping="wrap"  fontsize="20" verticalalignment="center" />                             </stackpanel>                             <stackpanel width="5"></stackpanel>                             <stackpanel width="150" orientation="horizontal" horizontalalignment="right">                                 <checkbox  ischecked="{binding chkflag, mode=twoway}"  borderbrush="#203485" foreground="black" borderthickness="1" tag="{binding cusnum}" name="cuscheck" checked="cuscheck_checked_2" unchecked="cuscheck_unchecked_2" ></checkbox>                                 <textblock text=" "  textwrapping="wrap" foreground="black" fontsize="20" verticalalignment="center" />                             </stackpanel>                         </stackpanel>                     </datatemplate>                 </listbox.itemtemplate>             </listbox> 

when check/select on checkbox checkbox checked event fires , when uncheck/unselect checkbox checkbox unchecked event fires.

but issuse is :-

when scrolling listbox checkbox checked , uncheked event fires automatically ??

how can avoid happen ??

please me out , looking forward response.

your issue relates fact binding ischecked property , have handlers checked , unchecked events. when binding updated , property changes cause events fire.

events fire each item when itemssource set/loaded.

by default listbox uses virtualizing container it's item panel. means scroll items loaded in , out of container , trigger events result of binding changing. why see more events being triggered while scroll. (assuming have sufficiently large list require virtualization.)

assuming chkflag property on viewmodel , cuscheck_checked_2 & cuscheck_unchecked_2 event handlers on view, make things simpler , avoid issue moving logic event handlers setter chkflag. (this improve ease of testability too.)

for example, have property this:

    public bool chkflag     {                 {             return this.chkflagfield;         }          set         {             if (this.chkflagfield != value)             {                 this.chkflagfield = value;                 this.raisepropertychanged();                  if (value)                 {                     // perform checked action                 }                 else                 {                     // perform unchecked action                 }             }         }     } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -