c# - How to programmatically add and remove bitmap effect storyboard to ContentControl -


i have following behavior unfinished. please note transitionelement contentcontrol.

i create 2 storyboards use blurbitmapeffect blur , unblur control.

if contentcontrol enabled property set false, add storyboards , begin blur.

if enabled set true, run storyboard unblurs control , once finished removes both storyboards, removing bitmap effects.

class contentcontrolbehavior : behavior<transitionelement> {     protected override void onattached()     {         base.onattached();         associatedobject.isenabledchanged += associatedobject_isenabledchanged;     }     protected override void ondetaching()     {         associatedobject.isenabledchanged -= associatedobject_isenabledchanged;         base.ondetaching();     }     void associatedobject_isenabledchanged(object sender, dependencypropertychangedeventargs e)     {         if ((bool)e.newvalue == false)         {             //blur         }         else         {             //unblur , remove storyboards , bitmap effects.         }     } } 

i doing when lock , unlock application.

i found doing through xaml styles had huge impact on graphical performance. found notes below. figure why not apply these storyboards , remove them altogther.

be careful using wpf bitmap effects. @ time i'm writing this, wpf bitmap effects rendered in software mode. object applies effect rendered in software. bitmap effects should not applied large visuals. also, animating properties of effect can degrade performance. @ time, suggest use bitmap effects sparingly , use them on relatively small visual ui objects buttons, text boxes, etc. feel free animate effects, again, recommend relatively small, subtle animations.

i have noticed bitmapeffect depreciated , effect 1 use.

here solution if not want remove storyboard @ end of unblur

assuming transitionelement kind of frameworkelement below sample.

class contentcontrolbehavior : behavior<transitionelement> {     protected override void onattached()     {         base.onattached();         associatedobject.isenabledchanged += associatedobject_isenabledchanged;         // add effect element         blureffect effect = new blureffect() { radius = 0 };         associatedobject.effect = effect;     }     protected override void ondetaching()     {         associatedobject.isenabledchanged -= associatedobject_isenabledchanged;         base.ondetaching();         //remove effect         associatedobject.effect = null;     }     void associatedobject_isenabledchanged(object sender, dependencypropertychangedeventargs e)     {         if ((bool)e.newvalue == false)         {             //blur             blureffect effect = associatedobject.effect blureffect;             effect.beginanimation(blureffect.radiusproperty, new doubleanimation(10, timespan.fromseconds(0.5)));         }         else         {             //unblur             blureffect effect = associatedobject.effect blureffect;             effect.beginanimation(blureffect.radiusproperty, new doubleanimation(0, timespan.fromseconds(0.25)));         }     } } 

in above example invoking beginanimation removes previous animation targeted property, last 1 remain, on effect , removed behavior detached.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

django - CSRF verification failed. Request aborted. CSRF cookie not set -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -