Skip to content

Commit ebcc04a

Browse files
committed
make a start on right hand drawer
1 parent 88fada5 commit ebcc04a

File tree

4 files changed

+194
-43
lines changed

4 files changed

+194
-43
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="MainWindow.xaml">
4+
StartupUri="ProvingGround.xaml">
55
<Application.Resources>
66
<ResourceDictionary>
77
<ResourceDictionary.MergedDictionaries>

MainDemo.Wpf/ProvingGround.xaml

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,17 @@
2828
</ResourceDictionary>
2929
</UserControl.Resources>
3030

31-
<materialDesign:DialogHost Identifier="RootDialog">
32-
<ScrollViewer VerticalScrollBarVisibility="Auto" Background="White">
33-
<Grid>
34-
<TextBox x:Name="loginText"
35-
materialDesign:HintAssist.FloatingScale=".56"
36-
materialDesign:HintAssist.FloatingOffset="1,-42"
37-
Style="{StaticResource MaterialDesignFloatingHintTextBox}" materialDesign:TextFieldAssist.TextBoxViewMargin="1 0 1 0" Margin="0,350,0,0" materialDesign:HintAssist.IsFloating="True" HorizontalAlignment="Center" VerticalAlignment="Top" Width="400" FontSize="36" Height="100" Background="White" Padding="6,0,0,2">
38-
<materialDesign:HintAssist.Hint>
39-
<StackPanel Orientation="Horizontal" Margin="0 0 0 0">
40-
<materialDesign:PackIcon Kind="Account" Width="50" Height="50" />
41-
<TextBlock Padding="5,0,0,0">Enter login</TextBlock>
42-
</StackPanel>
43-
</materialDesign:HintAssist.Hint>
44-
</TextBox>
31+
<materialDesign:DrawerHost>
32+
<materialDesign:DrawerHost.RightDrawerContent>
33+
<Grid Margin="16">
34+
<TextBlock> Hello World</TextBlock>
4535
</Grid>
46-
</ScrollViewer>
47-
</materialDesign:DialogHost>
36+
</materialDesign:DrawerHost.RightDrawerContent>
37+
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
38+
<Button Command="{x:Static materialDesign:DrawerHost.OpenDrawerCommand}">
39+
Open sesame
40+
</Button>
41+
</StackPanel>
42+
</materialDesign:DrawerHost>
4843

4944
</UserControl>

MaterialDesignThemes.Wpf/DrawerHost.cs

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ namespace MaterialDesignThemes.Wpf
1111
[TemplateVisualState(GroupName = TemplateAllDrawersGroupName, Name = TemplateAllDrawersAnyOpenStateName)]
1212
[TemplateVisualState(GroupName = TemplateLeftDrawerGroupName, Name = TemplateLeftClosedStateName)]
1313
[TemplateVisualState(GroupName = TemplateLeftDrawerGroupName, Name = TemplateLeftOpenStateName)]
14+
[TemplateVisualState(GroupName = TemplateRightDrawerGroupName, Name = TemplateRightClosedStateName)]
15+
[TemplateVisualState(GroupName = TemplateRightDrawerGroupName, Name = TemplateRightOpenStateName)]
1416
[TemplatePart(Name = TemplateContentCoverPartName, Type = typeof(FrameworkElement))]
1517
public class DrawerHost : ContentControl
1618
{
@@ -20,6 +22,9 @@ public class DrawerHost : ContentControl
2022
public const string TemplateLeftDrawerGroupName = "LeftDrawer";
2123
public const string TemplateLeftClosedStateName = "LeftDrawerClosed";
2224
public const string TemplateLeftOpenStateName = "LeftDrawerOpen";
25+
public const string TemplateRightDrawerGroupName = "RightDrawer";
26+
public const string TemplateRightClosedStateName = "RightDrawerClosed";
27+
public const string TemplateRightOpenStateName = "RightDrawerOpen";
2328

2429
public const string TemplateContentCoverPartName = "PART_ContentCover";
2530

@@ -93,6 +98,60 @@ public bool IsLeftDrawerOpen
9398
set { SetValue(IsLeftDrawerOpenProperty, value); }
9499
}
95100

101+
public static readonly DependencyProperty RightDrawerContentProperty = DependencyProperty.Register(
102+
nameof(RightDrawerContent), typeof(object), typeof(DrawerHost), new PropertyMetadata(default(object)));
103+
104+
public object RightDrawerContent
105+
{
106+
get { return (object)GetValue(RightDrawerContentProperty); }
107+
set { SetValue(RightDrawerContentProperty, value); }
108+
}
109+
110+
public static readonly DependencyProperty RightDrawerContentTemplateProperty = DependencyProperty.Register(
111+
nameof(RightDrawerContentTemplate), typeof(DataTemplate), typeof(DrawerHost), new PropertyMetadata(default(DataTemplate)));
112+
113+
public DataTemplate RightDrawerContentTemplate
114+
{
115+
get { return (DataTemplate)GetValue(RightDrawerContentTemplateProperty); }
116+
set { SetValue(RightDrawerContentTemplateProperty, value); }
117+
}
118+
119+
public static readonly DependencyProperty RightDrawerContentTemplateSelectorProperty = DependencyProperty.Register(
120+
nameof(RightDrawerContentTemplateSelector), typeof(DataTemplateSelector), typeof(DrawerHost), new PropertyMetadata(default(DataTemplateSelector)));
121+
122+
public DataTemplateSelector RightDrawerContentTemplateSelector
123+
{
124+
get { return (DataTemplateSelector)GetValue(RightDrawerContentTemplateSelectorProperty); }
125+
set { SetValue(RightDrawerContentTemplateSelectorProperty, value); }
126+
}
127+
128+
public static readonly DependencyProperty RightDrawerContentStringFormatProperty = DependencyProperty.Register(
129+
nameof(RightDrawerContentStringFormat), typeof(string), typeof(DrawerHost), new PropertyMetadata(default(string)));
130+
131+
public string RightDrawerContentStringFormat
132+
{
133+
get { return (string)GetValue(RightDrawerContentStringFormatProperty); }
134+
set { SetValue(RightDrawerContentStringFormatProperty, value); }
135+
}
136+
137+
public static readonly DependencyProperty RightDrawerBackgroundProperty = DependencyProperty.Register(
138+
nameof(RightDrawerBackground), typeof(Brush), typeof(DrawerHost), new PropertyMetadata(default(Brush)));
139+
140+
public Brush RightDrawerBackground
141+
{
142+
get { return (Brush)GetValue(RightDrawerBackgroundProperty); }
143+
set { SetValue(RightDrawerBackgroundProperty, value); }
144+
}
145+
146+
public static readonly DependencyProperty IsRightDrawerOpenProperty = DependencyProperty.Register(
147+
nameof(IsRightDrawerOpen), typeof(bool), typeof(DrawerHost), new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsRightDrawerOpenPropertyChangedCallback));
148+
149+
public bool IsRightDrawerOpen
150+
{
151+
get { return (bool)GetValue(IsRightDrawerOpenProperty); }
152+
set { SetValue(IsRightDrawerOpenProperty, value); }
153+
}
154+
96155
public override void OnApplyTemplate()
97156
{
98157
if (_templateContentCoverElement != null)
@@ -105,35 +164,44 @@ public override void OnApplyTemplate()
105164
_templateContentCoverElement.PreviewMouseLeftButtonUp += TemplateContentCoverElementOnPreviewMouseLeftButtonUp;
106165

107166

108-
UpdateVisualStates(false);
167+
UpdateVisualStates();
109168
}
110169

111170
private void TemplateContentCoverElementOnPreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
112171
{
113172
SetCurrentValue(IsLeftDrawerOpenProperty, false);
114173
}
115174

116-
private void UpdateVisualStates(bool useTransitions)
175+
private void UpdateVisualStates()
117176
{
118-
var anyOpen = IsLeftDrawerOpen;
177+
var anyOpen = IsLeftDrawerOpen || IsRightDrawerOpen;
119178

120179
VisualStateManager.GoToState(this,
121180
!anyOpen ? TemplateAllDrawersAllClosedStateName : TemplateAllDrawersAnyOpenStateName, !TransitionAssist.GetDisableTransitions(this));
122181

123182
VisualStateManager.GoToState(this,
124183
IsLeftDrawerOpen ? TemplateLeftOpenStateName : TemplateLeftClosedStateName, !TransitionAssist.GetDisableTransitions(this));
184+
185+
VisualStateManager.GoToState(this,
186+
IsRightDrawerOpen ? TemplateRightOpenStateName : TemplateRightClosedStateName, !TransitionAssist.GetDisableTransitions(this));
125187
}
126188

127189
private static void IsLeftDrawerOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
128190
{
129-
((DrawerHost)dependencyObject).UpdateVisualStates(true);
191+
((DrawerHost)dependencyObject).UpdateVisualStates();
130192
}
131193

194+
private static void IsRightDrawerOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
195+
{
196+
((DrawerHost)dependencyObject).UpdateVisualStates();
197+
}
198+
199+
132200
private void CloseDrawerHandler(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs)
133201
{
134202
if (executedRoutedEventArgs.Handled) return;
135203

136-
SetCurrentValue(IsLeftDrawerOpenProperty, false);
204+
SetOpenFlag(executedRoutedEventArgs, false);
137205

138206
executedRoutedEventArgs.Handled = true;
139207
}
@@ -142,9 +210,36 @@ private void OpenDrawerHandler(object sender, ExecutedRoutedEventArgs executedRo
142210
{
143211
if (executedRoutedEventArgs.Handled) return;
144212

145-
SetCurrentValue(IsLeftDrawerOpenProperty, true);
213+
SetOpenFlag(executedRoutedEventArgs, true);
146214

147215
executedRoutedEventArgs.Handled = true;
148216
}
217+
218+
private void SetOpenFlag(ExecutedRoutedEventArgs executedRoutedEventArgs, bool value)
219+
{
220+
if (executedRoutedEventArgs.Parameter is Dock)
221+
{
222+
switch ((Dock)executedRoutedEventArgs.Parameter)
223+
{
224+
case Dock.Left:
225+
SetCurrentValue(IsLeftDrawerOpenProperty, value);
226+
break;
227+
case Dock.Top:
228+
break;
229+
case Dock.Right:
230+
SetCurrentValue(IsRightDrawerOpenProperty, value);
231+
break;
232+
case Dock.Bottom:
233+
break;
234+
default:
235+
throw new ArgumentOutOfRangeException();
236+
}
237+
}
238+
else
239+
{
240+
SetCurrentValue(IsLeftDrawerOpenProperty, value);
241+
SetCurrentValue(IsRightDrawerOpenProperty, value);
242+
}
243+
}
149244
}
150245
}

0 commit comments

Comments
 (0)