Skip to content

Commit cb5b9c6

Browse files
committed
mucking about with the drawer visual states
1 parent ebcc04a commit cb5b9c6

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed

MainDemo.Wpf/App.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Application x:Class="MaterialDesignColors.WpfExample.App"
22
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4-
StartupUri="ProvingGround.xaml">
4+
StartupUri="MainWindow.xaml">
55
<Application.Resources>
66
<ResourceDictionary>
77
<ResourceDictionary.MergedDictionaries>

MainDemo.Wpf/ProvingGround.xaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,19 @@
3232
<materialDesign:DrawerHost.RightDrawerContent>
3333
<Grid Margin="16">
3434
<TextBlock> Hello World</TextBlock>
35+
<Button Command="{x:Static materialDesign:DrawerHost.CloseDrawerCommand}">
36+
Close
37+
</Button>
3538
</Grid>
3639
</materialDesign:DrawerHost.RightDrawerContent>
40+
<materialDesign:DrawerHost.LeftDrawerContent>
41+
<Grid Margin="16">
42+
<TextBlock>LEFT STUFF</TextBlock>
43+
<Button Command="{x:Static materialDesign:DrawerHost.CloseDrawerCommand}">
44+
Close
45+
</Button>
46+
</Grid>
47+
</materialDesign:DrawerHost.LeftDrawerContent>
3748
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
3849
<Button Command="{x:Static materialDesign:DrawerHost.OpenDrawerCommand}">
3950
Open sesame

MaterialDesignThemes.Wpf/Converters/DrawerOffsetConverter.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using System.Windows;
78
using System.Windows.Data;
89

910
namespace MaterialDesignThemes.Wpf.Converters
@@ -14,6 +15,13 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1415
{
1516
var d = value as double? ?? 0;
1617
if (double.IsInfinity(d) || double.IsNaN(d)) d = 0;
18+
19+
if (parameter is bool && (bool)parameter)
20+
{
21+
return 0 - d;
22+
//return new Thickness(0, 0, 0 - d, 0);
23+
}
24+
1725
return 0 - d;
1826
}
1927

MaterialDesignThemes.Wpf/DrawerHost.cs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,27 +163,26 @@ public override void OnApplyTemplate()
163163
if (_templateContentCoverElement != null)
164164
_templateContentCoverElement.PreviewMouseLeftButtonUp += TemplateContentCoverElementOnPreviewMouseLeftButtonUp;
165165

166-
167-
UpdateVisualStates();
166+
UpdateVisualStates(false);
168167
}
169168

170169
private void TemplateContentCoverElementOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
171170
{
172171
SetCurrentValue(IsLeftDrawerOpenProperty, false);
173172
}
174173

175-
private void UpdateVisualStates()
174+
private void UpdateVisualStates(bool? useTransitions = null)
176175
{
177176
var anyOpen = IsLeftDrawerOpen || IsRightDrawerOpen;
178177

179178
VisualStateManager.GoToState(this,
180-
!anyOpen ? TemplateAllDrawersAllClosedStateName : TemplateAllDrawersAnyOpenStateName, !TransitionAssist.GetDisableTransitions(this));
179+
!anyOpen ? TemplateAllDrawersAllClosedStateName : TemplateAllDrawersAnyOpenStateName, useTransitions.HasValue ? useTransitions.Value : !TransitionAssist.GetDisableTransitions(this));
181180

182181
VisualStateManager.GoToState(this,
183-
IsLeftDrawerOpen ? TemplateLeftOpenStateName : TemplateLeftClosedStateName, !TransitionAssist.GetDisableTransitions(this));
182+
IsLeftDrawerOpen ? TemplateLeftOpenStateName : TemplateLeftClosedStateName, useTransitions.HasValue ? useTransitions.Value : !TransitionAssist.GetDisableTransitions(this));
184183

185184
VisualStateManager.GoToState(this,
186-
IsRightDrawerOpen ? TemplateRightOpenStateName : TemplateRightClosedStateName, !TransitionAssist.GetDisableTransitions(this));
185+
IsRightDrawerOpen ? TemplateRightOpenStateName : TemplateRightClosedStateName, useTransitions.HasValue ? useTransitions.Value : !TransitionAssist.GetDisableTransitions(this));
187186
}
188187

189188
private static void IsLeftDrawerOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
@@ -196,7 +195,6 @@ private static void IsRightDrawerOpenPropertyChangedCallback(DependencyObject de
196195
((DrawerHost)dependencyObject).UpdateVisualStates();
197196
}
198197

199-
200198
private void CloseDrawerHandler(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs)
201199
{
202200
if (executedRoutedEventArgs.Handled) return;

MaterialDesignThemes.Wpf/Themes/Generic.xaml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
xmlns:local="clr-namespace:MaterialDesignThemes.Wpf"
55
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
66
xmlns:controlzEx="clr-namespace:ControlzEx"
7+
xmlns:sys="clr-namespace:System;assembly=mscorlib"
78
xmlns:transitions="clr-namespace:MaterialDesignThemes.Wpf.Transitions">
89

910
<ResourceDictionary.MergedDictionaries>
@@ -33,6 +34,7 @@
3334

3435
<converters:BrushToRadialGradientBrushConverter x:Key="BrushToRadialGradientBrushConverter" />
3536
<converters:DrawerOffsetConverter x:Key="DrawerOffsetConverter" />
37+
<sys:Boolean x:Key="True">True</sys:Boolean>
3638

3739
<Style TargetType="{x:Type local:Ripple}">
3840
<Setter Property="RecognizesAccessKey" Value="True" />
@@ -655,6 +657,7 @@
655657
<Style TargetType="{x:Type local:DrawerHost}">
656658
<Setter Property="local:ShadowAssist.ShadowDepth" Value="Depth3" />
657659
<Setter Property="LeftDrawerBackground" Value="{DynamicResource MaterialDesignPaper}" />
660+
<Setter Property="RightDrawerBackground" Value="{DynamicResource MaterialDesignPaper}" />
658661
<Setter Property="IsTabStop" Value="False" />
659662
<Setter Property="Template">
660663
<Setter.Value>
@@ -677,7 +680,7 @@
677680
<EasingDoubleKeyFrame.EasingFunction>
678681
<SineEase EasingMode="EaseOut" />
679682
</EasingDoubleKeyFrame.EasingFunction>
680-
</EasingDoubleKeyFrame>
683+
</EasingDoubleKeyFrame>
681684
</DoubleAnimationUsingKeyFrames>
682685
<ObjectAnimationUsingKeyFrames Storyboard.TargetName="PART_ContentCover"
683686
Storyboard.TargetProperty="Background">
@@ -728,7 +731,7 @@
728731
<VisualStateGroup.Transitions>
729732
<VisualTransition From="LeftDrawerClosed" To="LeftDrawerOpen">
730733
<Storyboard>
731-
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="X" Storyboard.TargetName="LeftDrawerTranslateTransform">
734+
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="X" Storyboard.TargetName="LeftDrawerTranslateTransform_">
732735
<EasingDoubleKeyFrame Value="0" KeyTime="0:0:0.4">
733736
<EasingDoubleKeyFrame.EasingFunction>
734737
<SineEase EasingMode="EaseOut" />
@@ -759,6 +762,7 @@
759762
</VisualStateGroup>
760763
<VisualStateGroup x:Name="RightDrawer">
761764
<VisualStateGroup.Transitions>
765+
<!--
762766
<VisualTransition From="RightDrawerClosed" To="RightDrawerOpen">
763767
<Storyboard>
764768
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="X" Storyboard.TargetName="RightDrawerTranslateTransform">
@@ -788,6 +792,7 @@
788792
</DoubleAnimationUsingKeyFrames>
789793
</Storyboard>
790794
</VisualTransition>
795+
-->
791796
</VisualStateGroup.Transitions>
792797
<VisualState x:Name="LeftDrawerOpen">
793798
<Storyboard>
@@ -801,6 +806,7 @@
801806
<DoubleAnimation Storyboard.TargetProperty="X" Storyboard.TargetName="LeftDrawerTranslateTransform" Duration="0"/>
802807
</Storyboard>
803808
</VisualState>
809+
<!--
804810
<VisualState x:Name="RightDrawerOpen">
805811
<Storyboard>
806812
<DoubleAnimation Storyboard.TargetName="RightDrawerShadow" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0" />
@@ -813,12 +819,14 @@
813819
<DoubleAnimation Storyboard.TargetProperty="X" Storyboard.TargetName="RightDrawerTranslateTransform" Duration="0"/>
814820
</Storyboard>
815821
</VisualState>
822+
-->
816823
</VisualStateGroup>
817824
</VisualStateManager.VisualStateGroups>
818825
<AdornerDecorator>
819826
<ContentPresenter
820-
x:Name="ContentPresenter" Opacity="1"
821-
Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentStringFormat="{TemplateBinding ContentStringFormat}" />
827+
x:Name="ContentPresenter"
828+
Opacity="1"
829+
Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" ContentStringFormat="{TemplateBinding ContentStringFormat}" />
822830
</AdornerDecorator>
823831
<Grid x:Name="PART_ContentCover" Background="{x:Null}" Opacity="0" IsHitTestVisible="False" Focusable="False" />
824832
<Grid HorizontalAlignment="Left" VerticalAlignment="Stretch">
@@ -838,10 +846,11 @@
838846
</AdornerDecorator>
839847
<ContentPresenter Content="{TemplateBinding LeftDrawerContent}" ContentTemplate="{TemplateBinding LeftDrawerContentTemplate}" ContentStringFormat="{TemplateBinding LeftDrawerContentStringFormat}" />
840848
</Grid>
841-
<Grid HorizontalAlignment="Right" VerticalAlignment="Stretch">
849+
<!--
850+
<Grid VerticalAlignment="Stretch" HorizontalAlignment="Right">
842851
<Grid.RenderTransform>
843852
<TranslateTransform x:Name="RightDrawerTranslateTransform"
844-
X="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType=Grid}, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}}" />
853+
X="{Binding ElementName=RootGrid, Path=ActualWidth, Converter={StaticResource DrawerOffsetConverter}, ConverterParameter={StaticResource True}}" />
845854
</Grid.RenderTransform>
846855
<AdornerDecorator>
847856
<AdornerDecorator.CacheMode>
@@ -855,6 +864,7 @@
855864
</AdornerDecorator>
856865
<ContentPresenter Content="{TemplateBinding RightDrawerContent}" ContentTemplate="{TemplateBinding RightDrawerContentTemplate}" ContentStringFormat="{TemplateBinding RightDrawerContentStringFormat}" />
857866
</Grid>
867+
-->
858868
</Grid>
859869
</ControlTemplate>
860870
</Setter.Value>

0 commit comments

Comments
 (0)