Animate Expander in WPF

后端 未结 2 1702
予麋鹿
予麋鹿 2020-12-10 01:02

How to animate the expanded and collapsed actions of a Wpf expander control?

2条回答
  •  半阙折子戏
    2020-12-10 01:34

    I created a style based on msdn Style and the point in this answer:

     
    
    
        #FFE8EDF9
        #FFC5CBF9
        #FF7381F9
    
        #FFE8EDF9
        #FFC5CBF9
        #FF888888
    
        #FFC5CBF9
        #FFDDDDDD
    
        White
        #FF7381F9
        #FF211AA9
    
        #FF3843C4
        #FF211AA9
    
    
        #FF444444
        sc#1, 0.004391443, 0.002428215, 0.242281124
    
        
        #FFCCCCCC
        #FF888888
        #FF444444
    
        #FF888888
        #FF444444
    
        #FFAAAAAA
        #FF888888
    
        Black
    
        
        #FFC5CBF9
        Black
        #FFC5CBF9
    
        #FF3843C4
    
        
            
            
            
        
    
        
            
                
                    
                    
                    
                    
                
            
        
    
        
            
                
                    
                        
                        
                    
                
                
                    
                        
                            
                                
                                
                            
                        
                    
    
                
                
                    
                        
                        
                            
                                
                                    
                                
                            
                        
                        
                            
                                
                                    
                                
                            
                        
                        
                            
                                
                                    
                                
                                
                                    
                                
                            
                        
                    
                    
                        
                            
                                
                                    
                                
                                
                                    
                                
                            
                        
                        
                        
                    
                
                
                    
                        
                            
                        
                    
                    
                        
                            
                        
                    
                
            
        
    
        
    
      
        
            
                

    Which requires this converter:

    public class MultiplyConverter : IMultiValueConverter
    {
        public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
        {
            return new GridLength((double)values[0] * (double)values[1], GridUnitType.Pixel);
        }
    
        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    The main point is to set DoubleAnimation on ContentRow.Height in the template. However, you need to use a MultiBinding to bind the To property of this animation.

提交回复
热议问题