c# - Disabling VisualStates in code behind - WP8 -


how can disable visualstate animations on listbox in code behind? i've created selected , unselected visualstate storyboard animation listboxitem when listbox itemssource changes listbox selected , unselected animation performed (i think items selected , unselected second automatically).

edit: found workaround solution - if you're getting selected , unselected animations on items source changing can use it. seems automated selection changes doesn't raise selectionchanged event.

public class listboxselectedfoldersanimationbehaviour : behavior<listbox> {     protected override void onattached()     {         base.onattached();         associatedobject.selectionchanged += listboxonselectionchanged;     }      protected override void ondetaching()     {         base.ondetaching();         associatedobject.selectionchanged -= listboxonselectionchanged;     }      private void listboxonselectionchanged(object sender, selectionchangedeventargs selectionchangedeventargs)     {         foreach (var item in selectionchangedeventargs.addeditems)         {             var listboxitem = associatedobject.itemcontainergenerator.containerfromitem(item) listboxitem;             if (listboxitem != null)                 setitemselectedanimation(listboxitem);         }          foreach (var item in selectionchangedeventargs.removeditems)         {             var listboxitem = associatedobject.itemcontainergenerator.containerfromitem(item) listboxitem;             if (listboxitem != null) // listboxitem can null after removing item listbox.itemssource                 setitemunselectedanimation(listboxitem);         }     }      private void setitemselectedanimation(listboxitem item)     { // sample opacity animation         var storyboard = new storyboard();         var fadeoutanimation = new doubleanimation()         {             easingfunction = new cubicease() { easingmode = easingmode.easeout },             duration = new duration(timespan.frommilliseconds(200)),             = 1.0,             = 0.6         };         storyboard.children.add(fadeoutanimation);         storyboard.settarget(storyboard, item);         storyboard.settargetproperty(storyboard, new propertypath(listboxitem.opacityproperty));         storyboard.begin();     }      private void setitemunselectedanimation(listboxitem item)     { // sample opacity animation         var storyboard = new storyboard();         var fadeinanimation = new doubleanimation()         {             easingfunction = new cubicease() { easingmode = easingmode.easein },             duration = new duration(timespan.frommilliseconds(200)),             = 0.6,             = 1.0         };         storyboard.children.add(fadeinanimation);         storyboard.settarget(storyboard, item);         storyboard.settargetproperty(storyboard, new propertypath(listboxitem.opacityproperty));         storyboard.begin();     } }   xaml: <page xmlns:i="clr-namespace:system.windows.interactivity;assembly=system.windows.interactivity"       xmlns:classnamespace="clr-namespace:yourprojectname.namespaceofbehaviourclass"> ...  <listbox>     <i:interaction.behaviors>         <classnamespace:listboxselectedfoldersanimationbehaviour/>     </i:interaction.behaviors> </listbox>  

i haven't checked leaks memory yet (cause i'm not stopping storyboards) keep in mind.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -