none
Transparent Window Opacity Animation Very Slow

    Question

  • Hi Folks,

     

    I'm working on a WPF application at the moment and for next phase had been hoping to add some nice transitions between windows.  Specifically I wanted to try a fade in/fade out effect.  Using the following code I can get a fairly smoothe fade in from the new window.

     

    DoubleAnimation animFadeIn = new DoubleAnimation();

    animFadeIn.From = 0;

    animFadeIn.To = 1;

    animFadeIn.Duration = new Duration(TimeSpan.FromSeconds(0.5));

    window.Show();

    window.BeginAnimation(Window.OpacityProperty, animFadeIn);

    lsWindows[lsWindows.Count - 2].Hide();

     

    This hides the previous window in the stack and then fades in the new window from a fixed black colour to the final window.  It works, it's speedy - but the lack of a transparent background on the window means two things:

     

    1. It starts from a fixed black colour

    2. You cannot perform any fade out effect on the old window.

     

    If, before calling window.show() I do a

     

    window.AllowsTransparency = true;

     

    I then get the lack of background meaning I can see the previous window.  It also permits me to then run a second animation on the old window changing opacity from 1 to 0 if I want to.

     

    There is, however, a big problem with this - it is PAINFULLY slow.  I'm running this on a Dual Core 2GHz, 2GB RAM, 256mb VRAM Radeon Mobile x1600 system about 18 months old with Vista, in the field this will have to run on significantly lower spec machines with onboard graphics.  On my system the animation is incredibly jerky - getting about 2 or 3 frames in the 0.5 seconds so that the animation looks horrid.  That's just running the fade in animation.  If I try and fade out the other window at the same time it gets (unsurprisingly) even more jerky.

     

    I've tried writing my own thread that updates the opacity, rather than using Opacity and a Double Animation - this was slightly better but still far below what I'd want - and certainly not an ideal solution.

     

    I know setting a window to have a transparent background is a bit of a hog - but this seems a bit over the top.  Is there either:

     

    1. A better way to fade one window out as the other fades in than using AllowsTransparency=true

     

    or

     

    2. An alternative animation technique I am using above with a doubleanimation changing opacity

     

    Any answers would be greatly appreciated :-)

     

    Thanks and regards,

     

    Guy Powell

    Friday, January 11, 2008 1:19 AM

Answers

All replies

  • For Vista, you need this patch.

     

    (And for XP/2003, you need this patch, in case others are having similar issues on those platforms.)

    Friday, January 11, 2008 1:39 AM
  • Dr. WPF,

     

    Thanks for that - after waiting a few hours for MS to get the HotFix details sent over to me it works a treat on Vista now on my main development machine.

     

    I'm yet to try this one on XP on a low spec (500MHz non-3D system) so it will be interesting to see how well that works.

     

    Only thing I'll add for others is that this HotFix is not redistributable, nor available for download from MS without registration and waiting 8 hours or so at the moment - so if you're planning on using these in your apps for mass-release it may be worth waiting a few weeks (I've heard we can expect something in next 2-3 weeks) for the HotFix to go into mainstream release, or even Vista SP1/XP SP3 which should include it.

     

    Thanks again Dr. WPF :-)

     

    Rgds,

     

    Guy

    Friday, January 11, 2008 2:45 PM