WPF Fade Out Animation - Can't Change Opacity Any More

后端 未结 2 1546
醉梦人生
醉梦人生 2021-01-05 18:41

I have a WPF window with a label control used for messages to the user. After a few seconds, I want the message to fade away. I have created a DispatcherTimer

2条回答
  •  半阙折子戏
    2021-01-05 19:00

    Its due to the "fill behavior" of the animation. It's effectively holding on to the value after the animation and not letting go, preventing it from being updated.

    Its an easy fix, change the fill behavior to stop and add an event handler to change the opacity value to 0 after the animation (otherwise it will go back to 1)

    animation.FillBehavior = FillBehavior.Stop;
    animation.Completed += delegate 
    {
        lblTest.Opacity = 0;
    };
    

    I have tested this with your code and it worked.

    Ben

提交回复
热议问题