Skip to content

Commit d304968

Browse files
committed
move left drawer over to new margin animation
1 parent 9e9cbb9 commit d304968

File tree

3 files changed

+29
-22
lines changed

3 files changed

+29
-22
lines changed

MaterialDesignThemes.Wpf/Converters/DrawerOffsetConverter.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Text;
66
using System.Threading.Tasks;
77
using System.Windows;
8+
using System.Windows.Controls;
89
using System.Windows.Data;
910

1011
namespace MaterialDesignThemes.Wpf.Converters
@@ -16,12 +17,19 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1617
var d = value as double? ?? 0;
1718
if (double.IsInfinity(d) || double.IsNaN(d)) d = 0;
1819

19-
if (parameter is bool && (bool)parameter)
20+
var dock = (parameter is Dock) ? (Dock)parameter : Dock.Left;
21+
switch (dock)
2022
{
21-
return new Thickness(0, 0, 0 - d, 0);
23+
case Dock.Top:
24+
return new Thickness(0, 0 - d, 0, 0);
25+
case Dock.Bottom:
26+
return new Thickness(0, 0, 0, 0 - d);
27+
case Dock.Right:
28+
return new Thickness(0, 0, 0 - d, 0);
29+
case Dock.Left:
30+
default:
31+
return new Thickness(0 - d, 0, 0, 0);
2232
}
23-
24-
return 0 - d;
2533
}
2634

2735
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)

MaterialDesignThemes.Wpf/DrawerHost.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ public override void OnApplyTemplate()
169169
private void TemplateContentCoverElementOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
170170
{
171171
SetCurrentValue(IsLeftDrawerOpenProperty, false);
172+
SetCurrentValue(IsRightDrawerOpenProperty, false);
172173
}
173174

174175
private void UpdateVisualStates(bool? useTransitions = null)

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -732,23 +732,23 @@
732732
<VisualStateGroup.Transitions>
733733
<VisualTransition From="LeftDrawerClosed" To="LeftDrawerOpen">
734734
<Storyboard>
735-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="X" Storyboard.TargetName="LeftDrawerTranslateTransform">
736-
<EasingDoubleKeyFrame Value="0" KeyTime="0:0:0.4">
737-
<EasingDoubleKeyFrame.EasingFunction>
735+
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="Margin" Storyboard.TargetName="LeftDrawerGrid">
736+
<EasingThicknessKeyFrame Value="0" KeyTime="0:0:0.4">
737+
<EasingThicknessKeyFrame.EasingFunction>
738738
<SineEase EasingMode="EaseOut" />
739-
</EasingDoubleKeyFrame.EasingFunction>
740-
</EasingDoubleKeyFrame>
741-
</DoubleAnimationUsingKeyFrames>
739+
</EasingThicknessKeyFrame.EasingFunction>
740+
</EasingThicknessKeyFrame>
741+
</ThicknessAnimationUsingKeyFrames>
742742
<DoubleAnimation Storyboard.TargetName="LeftDrawerShadow" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:0.04" />
743743
</Storyboard>
744744
</VisualTransition>
745745
<VisualTransition From="LeftDrawerOpen" To="LeftDrawerClosed">
746746
<Storyboard>
747-
<DoubleAnimation Storyboard.TargetProperty="X" Storyboard.TargetName="LeftDrawerTranslateTransform" Duration="0:0:0.4">
748-
<DoubleAnimation.EasingFunction>
747+
<ThicknessAnimation Storyboard.TargetProperty="Margin" Storyboard.TargetName="LeftDrawerGrid" Duration="0:0:0.4">
748+
<ThicknessAnimation.EasingFunction>
749749
<SineEase EasingMode="EaseOut" />
750-
</DoubleAnimation.EasingFunction>
751-
</DoubleAnimation>
750+
</ThicknessAnimation.EasingFunction>
751+
</ThicknessAnimation>
752752
<DoubleAnimationUsingKeyFrames Storyboard.TargetName="LeftDrawerShadow" Storyboard.TargetProperty="Opacity">
753753
<EasingDoubleKeyFrame Value="1" KeyTime="0:0:0.36" />
754754
<EasingDoubleKeyFrame Value="0" KeyTime="0:0:0.4">
@@ -763,13 +763,13 @@
763763
<VisualState x:Name="LeftDrawerOpen">
764764
<Storyboard>
765765
<DoubleAnimation Storyboard.TargetName="LeftDrawerShadow" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0" />
766-
<DoubleAnimation Storyboard.TargetProperty="X" Storyboard.TargetName="LeftDrawerTranslateTransform" To="0" Duration="0"/>
766+
<ThicknessAnimation Storyboard.TargetProperty="Margin" Storyboard.TargetName="LeftDrawerGrid" To="0" Duration="0"/>
767767
</Storyboard>
768768
</VisualState>
769769
<VisualState x:Name="LeftDrawerClosed">
770770
<Storyboard>
771771
<DoubleAnimation Storyboard.TargetName="LeftDrawerShadow" Storyboard.TargetProperty="Opacity" From="0" To="0" Duration="0" />
772-
<DoubleAnimation Storyboard.TargetProperty="X" Storyboard.TargetName="LeftDrawerTranslateTransform" Duration="0"/>
772+
<ThicknessAnimation Storyboard.TargetProperty="Margin" Storyboard.TargetName="LeftDrawerGrid" Duration="0"/>
773773
</Storyboard>
774774
</VisualState>
775775
</VisualStateGroup>
@@ -825,11 +825,9 @@
825825
Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentStringFormat="{TemplateBinding ContentStringFormat}" />
826826
</AdornerDecorator>
827827
<Grid x:Name="PART_ContentCover" Background="{x:Null}" Opacity="0" IsHitTestVisible="False" Focusable="False" />
828-
<Grid HorizontalAlignment="Left" VerticalAlignment="Stretch">
829-
<Grid.RenderTransform>
830-
<TranslateTransform x:Name="LeftDrawerTranslateTransform"
831-
X="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Grid}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}}" />
832-
</Grid.RenderTransform>
828+
<Grid HorizontalAlignment="Left" VerticalAlignment="Stretch"
829+
x:Name="LeftDrawerGrid"
830+
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Left}}">
833831
<AdornerDecorator>
834832
<AdornerDecorator.CacheMode>
835833
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>
@@ -844,7 +842,7 @@
844842
</Grid>
845843
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Right"
846844
x:Name="RightDrawerGrid"
847-
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={StaticResource True}}">
845+
Margin="{Binding RelativeSource={RelativeSource Self}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={x:Static Dock.Right}}">
848846
<AdornerDecorator>
849847
<AdornerDecorator.CacheMode>
850848
<BitmapCache EnableClearType="True" SnapsToDevicePixels="True"/>

0 commit comments

Comments
 (0)