c# - Fading out a window -


i developing wpf c# application. have added event triggers xaml of form fade in when window loads , fades out when window closes.

the fading in works without problems fading out not working.

i have set window fades in when loads, has timer last 5 seconds, , calls form fade out event.

however, window doesn't fade out closes straight away no animation. below code have fade in , fade out events

<window.triggers>         <eventtrigger routedevent="window.loaded">             <beginstoryboard>                 <storyboard name="formfade">                     <doubleanimation name="formfadeanimation"                                      storyboard.targetproperty="(window.opacity)"                                      from="0.0" to="1.0" duration="0:0:1"                                      autoreverse="false" repeatbehavior="1x" />                 </storyboard>             </beginstoryboard>         </eventtrigger>         <eventtrigger routedevent="window.unloaded">             <beginstoryboard>                 <storyboard name="formfadeout" completed="formfadeout_completed">                     <doubleanimation name="formfadeoutanimation"                                      storyboard.targetname="formfadeout"                                      storyboard.targetproperty="(window.opacity)"                                      from="1.0" to="0.0" duration="0:0:1"                                      autoreverse="false" repeatbehavior="1x" />                 </storyboard>             </beginstoryboard>         </eventtrigger>     </window.triggers> 

thanks can offer.

unloaded not suitable event this, i'm not sure if event can occur windows. need handle closing, prevent closing, start animation , close when completed event of animation occurs.

e.g.

<window ...         closing="window_closing"> 
private void window_closing(object sender, canceleventargs e) {     closing -= window_closing;     e.cancel = true;     var anim = new doubleanimation(0, (duration)timespan.fromseconds(1));     anim.completed += (s, _) => this.close();     this.beginanimation(uielement.opacityproperty, anim); } 

Comments

Popular posts from this blog

c# - how to write client side events functions for the combobox items -

exception - Python, pyPdf OCR error: pyPdf.utils.PdfReadError: EOF marker not found -