Skip to content

Commit b791505

Browse files
committed
Improve expander animation
1 parent e1d83ca commit b791505

File tree

1 file changed

+34
-54
lines changed

1 file changed

+34
-54
lines changed

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Expander.xaml

Lines changed: 34 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3-
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf">
3+
xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf"
4+
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
5+
xmlns:system="clr-namespace:System;assembly=mscorlib">
6+
7+
<converters:MathMultipleConverter x:Key="MathMlpMultipleConverter" Operation="Multiply" />
48

59
<Style x:Key="MaterialDesignExpanderToggleButton" TargetType="{x:Type ToggleButton}">
610
<Setter Property="Width" Value="16"/>
@@ -117,67 +121,40 @@
117121
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Visibility">
118122
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
119123
</ObjectAnimationUsingKeyFrames>
120-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content">
121-
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
122-
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
123-
</DoubleAnimationUsingKeyFrames>
124-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="PART_Content">
125-
<EasingDoubleKeyFrame KeyTime="0" Value=".5"/>
126-
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
127-
</DoubleAnimationUsingKeyFrames>
128-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="PART_Content">
129-
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
130-
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
131-
</DoubleAnimationUsingKeyFrames>
124+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content"
125+
To="1" Duration="0:0:0.3"/>
126+
<DoubleAnimation Storyboard.TargetProperty="Tag" Storyboard.TargetName="ItemsScrollViewer"
127+
To="1" Duration="0:0:0.3"/>
132128
</Storyboard>
133129
</VisualTransition>
134130
<VisualTransition GeneratedDuration="0" To="Collapsed">
131+
<VisualTransition.GeneratedEasingFunction>
132+
<CubicEase EasingMode="EaseOut"/>
133+
</VisualTransition.GeneratedEasingFunction>
135134
<Storyboard>
136135
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Visibility">
137-
<DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Collapsed}" />
136+
<DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Collapsed}" />
138137
</ObjectAnimationUsingKeyFrames>
139-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content">
140-
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
141-
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0"/>
142-
</DoubleAnimationUsingKeyFrames>
143-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="PART_Content">
144-
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
145-
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value=".5"/>
146-
</DoubleAnimationUsingKeyFrames>
147-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="PART_Content">
148-
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
149-
<EasingDoubleKeyFrame KeyTime="0:0:0.5" Value="0"/>
150-
</DoubleAnimationUsingKeyFrames>
138+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content"
139+
To="0" Duration="0:0:0.3"/>
140+
<DoubleAnimation Storyboard.TargetProperty="Tag" Storyboard.TargetName="ItemsScrollViewer"
141+
To="0" Duration="0:0:0.3"/>
151142
</Storyboard>
152143
</VisualTransition>
153144
</VisualStateGroup.Transitions>
154145
<VisualState x:Name="Expanded">
155146
<Storyboard>
156-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content">
157-
<EasingDoubleKeyFrame KeyTime="0" Value="1"/>
158-
</DoubleAnimationUsingKeyFrames>
159-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="PART_Content">
160-
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="1"/>
161-
</DoubleAnimationUsingKeyFrames>
162-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="PART_Content">
163-
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="1"/>
164-
</DoubleAnimationUsingKeyFrames>
147+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content" To="1" Duration="0"/>
148+
<DoubleAnimation Storyboard.TargetProperty="Tag" Storyboard.TargetName="ItemsScrollViewer" To="1" Duration="0"/>
165149
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Visibility">
166150
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
167151
</ObjectAnimationUsingKeyFrames>
168152
</Storyboard>
169153
</VisualState>
170154
<VisualState x:Name="Collapsed">
171155
<Storyboard>
172-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content">
173-
<EasingDoubleKeyFrame KeyTime="0" Value="0"/>
174-
</DoubleAnimationUsingKeyFrames>
175-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="PART_Content">
176-
<EasingDoubleKeyFrame KeyTime="0:0:0" Value=".5"/>
177-
</DoubleAnimationUsingKeyFrames>
178-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.LayoutTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="PART_Content">
179-
<EasingDoubleKeyFrame KeyTime="0:0:0" Value="0"/>
180-
</DoubleAnimationUsingKeyFrames>
156+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content" To="0" Duration="0"/>
157+
<DoubleAnimation Storyboard.TargetProperty="Tag" Storyboard.TargetName="ItemsScrollViewer" To="0" Duration="0"/>
181158
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Visibility">
182159
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}" />
183160
</ObjectAnimationUsingKeyFrames>
@@ -205,16 +182,19 @@
205182
</Grid>
206183
</Border>
207184
<Border Grid.Row="1">
208-
<ContentPresenter Name="PART_Content" RenderTransformOrigin="0,0">
209-
<ContentPresenter.LayoutTransform>
210-
<TransformGroup>
211-
<ScaleTransform ScaleX="0.5" ScaleY="0" />
212-
<SkewTransform />
213-
<RotateTransform />
214-
<TranslateTransform />
215-
</TransformGroup>
216-
</ContentPresenter.LayoutTransform>
217-
</ContentPresenter>
185+
<ScrollViewer x:Name="ItemsScrollViewer"
186+
VerticalScrollBarVisibility="Hidden">
187+
<ScrollViewer.Tag>
188+
<system:Double>0.0</system:Double>
189+
</ScrollViewer.Tag>
190+
<ScrollViewer.Height>
191+
<MultiBinding Converter="{StaticResource MathMlpMultipleConverter}">
192+
<Binding ElementName="PART_Content" Path="ActualHeight"/>
193+
<Binding RelativeSource="{RelativeSource Self}" Path="Tag"/>
194+
</MultiBinding>
195+
</ScrollViewer.Height>
196+
<ContentPresenter Name="PART_Content" />
197+
</ScrollViewer>
218198
</Border>
219199
</Grid>
220200
</ControlTemplate>

0 commit comments

Comments
 (0)