Achieve “slide down” animation in WPF

后端 未结 3 1107
我在风中等你
我在风中等你 2020-12-15 09:33

I am attempting to create my own template for an Expander control. When the control is expanded, I want the content to slide down slowly.

The desired he

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 09:42

    If you can use Interactions with FluidLayout (Blend 4 SDK) you are in luck, it's really useful for those fancy animation things.

    First set the content CP's Height to 0:

    
    

    To animate this, the Height just needs to be animated to NaN in the VisualState that represents the expanded state (non-discrete animations would not let you use NaN):

    xmlns:is="http://schemas.microsoft.com/expression/2010/interactions"
    
    
        
            
        
        
            
                
                    
                
                
                    
                        
                            
                        
                    
                
                
            
        
        
    

    That should be all that is necessary, the fluid layout will create the transition for you from there.


    If you have a code-behind solution that would be fine, you can even use code-behind in dictionaries like this:

    
    
    
    //TestDictionary.xaml.cs
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Windows;
    
    namespace Test
    {
        partial class TestDictionary : ResourceDictionary
        {
            //Handlers and such here
        }
    }
    

提交回复
热议问题