Skip to content

Commit 056cf9d

Browse files
committed
Merge branch 'ExpanderAnimation' of https://github.com/l1pton17/MaterialDesignInXamlToolkit into l1pton17-ExpanderAnimation
2 parents c632337 + b8783d8 commit 056cf9d

File tree

2 files changed

+42
-58
lines changed

2 files changed

+42
-58
lines changed

MainDemo.Wpf/Expander.xaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616
<Expander.Header>
1717
<TextBlock Text="Expander Example 1" />
1818
</Expander.Header>
19-
<Border Background="{StaticResource MaterialDesignBackground}" CornerRadius="5" Padding="5">
20-
<StackPanel Orientation="Vertical">
19+
<Border Background="{DynamicResource MaterialDesignBody}"
20+
CornerRadius="5" Padding="5">
21+
<StackPanel Orientation="Vertical"
22+
TextBlock.Foreground="{DynamicResource MaterialDesignPaper}">
2123
<TextBlock Text="A short text to proof functionality." />
2224
<TextBlock Margin="0,50,0,0" Text="A short text to proof functionality." />
2325
</StackPanel>

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.Expander.xaml

Lines changed: 38 additions & 56 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"/>
@@ -102,6 +106,7 @@
102106

103107
<Style x:Key="MaterialDesignExpander" TargetType="{x:Type Expander}">
104108
<Setter Property="Background" Value="{StaticResource MaterialDesignPaper}" />
109+
<Setter Property="Foreground" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type FrameworkElement}}, Path=(TextElement.Foreground)}"/>
105110
<Setter Property="Template">
106111
<Setter.Value>
107112
<ControlTemplate TargetType="{x:Type Expander}">
@@ -117,67 +122,40 @@
117122
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Visibility">
118123
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
119124
</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>
125+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content"
126+
To="1" Duration="0:0:0.3"/>
127+
<DoubleAnimation Storyboard.TargetProperty="Tag" Storyboard.TargetName="ItemsScrollViewer"
128+
To="1" Duration="0:0:0.3"/>
132129
</Storyboard>
133130
</VisualTransition>
134131
<VisualTransition GeneratedDuration="0" To="Collapsed">
132+
<VisualTransition.GeneratedEasingFunction>
133+
<CubicEase EasingMode="EaseOut"/>
134+
</VisualTransition.GeneratedEasingFunction>
135135
<Storyboard>
136136
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Visibility">
137-
<DiscreteObjectKeyFrame KeyTime="0:0:0.5" Value="{x:Static Visibility.Collapsed}" />
137+
<DiscreteObjectKeyFrame KeyTime="0:0:0.3" Value="{x:Static Visibility.Collapsed}" />
138138
</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>
139+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content"
140+
To="0" Duration="0:0:0.3"/>
141+
<DoubleAnimation Storyboard.TargetProperty="Tag" Storyboard.TargetName="ItemsScrollViewer"
142+
To="0" Duration="0:0:0.3"/>
151143
</Storyboard>
152144
</VisualTransition>
153145
</VisualStateGroup.Transitions>
154146
<VisualState x:Name="Expanded">
155147
<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>
148+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content" To="1" Duration="0"/>
149+
<DoubleAnimation Storyboard.TargetProperty="Tag" Storyboard.TargetName="ItemsScrollViewer" To="1" Duration="0"/>
165150
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Visibility">
166151
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
167152
</ObjectAnimationUsingKeyFrames>
168153
</Storyboard>
169154
</VisualState>
170155
<VisualState x:Name="Collapsed">
171156
<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>
157+
<DoubleAnimation Storyboard.TargetProperty="Opacity" Storyboard.TargetName="PART_Content" To="0" Duration="0"/>
158+
<DoubleAnimation Storyboard.TargetProperty="Tag" Storyboard.TargetName="ItemsScrollViewer" To="0" Duration="0"/>
181159
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_Content" Storyboard.TargetProperty="Visibility">
182160
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}" />
183161
</ObjectAnimationUsingKeyFrames>
@@ -196,25 +174,29 @@
196174
<ColumnDefinition Width="100*" />
197175
</Grid.ColumnDefinitions>
198176
<ToggleButton IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
199-
Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}}" OverridesDefaultStyle="True"
177+
OverridesDefaultStyle="True"
200178
Style="{StaticResource MaterialDesignExpanderToggleButton}" />
201-
<ToggleButton Grid.Column="1" IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
179+
<ToggleButton Grid.Column="1"
180+
IsChecked="{Binding Path=IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
202181
Style="{StaticResource MaterialDesignExpanderHeaderToggleButton}">
203182
<ContentPresenter ContentSource="Header" HorizontalAlignment="Stretch" RecognizesAccessKey="True" VerticalAlignment="Center" />
204183
</ToggleButton>
205184
</Grid>
206185
</Border>
207186
<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>
187+
<ScrollViewer x:Name="ItemsScrollViewer"
188+
VerticalScrollBarVisibility="Hidden">
189+
<ScrollViewer.Tag>
190+
<system:Double>0.0</system:Double>
191+
</ScrollViewer.Tag>
192+
<ScrollViewer.Height>
193+
<MultiBinding Converter="{StaticResource MathMlpMultipleConverter}">
194+
<Binding ElementName="PART_Content" Path="ActualHeight"/>
195+
<Binding RelativeSource="{RelativeSource Self}" Path="Tag"/>
196+
</MultiBinding>
197+
</ScrollViewer.Height>
198+
<ContentPresenter Name="PART_Content" />
199+
</ScrollViewer>
218200
</Border>
219201
</Grid>
220202
</ControlTemplate>

0 commit comments

Comments
 (0)