WPF Fade Animation

后端 未结 7 1350
余生分开走
余生分开走 2020-11-30 00:16

How would I make a control fade in/out when it becomes Visible.

Below is my failed attempt:



        
7条回答
  •  心在旅途
    2020-11-30 01:05

    You can't directly use the Visibility property for a fade out because setting a trigger on it will first Hide/Collapse the control, THEN animate it. So basically you'll got an animation on a collapsed control => nothing.

    One "reliable" way would be to introduce a new Dependency Property (attached or not), say IsOpen and setting a property trigger IsOpen=True on it with:

    EnterAction:
    • Make sure Visibility is set to Visible
    • Fade in the Opacity from 0 to 1
    ExitAction:
    • Visibility set to Visible at keyframe 0 and Collapsed/Hidden at the last Keyframe
    • Fade out the Opacity from 1 to 0.

    Here's an example:

    
    

提交回复
热议问题