@@ -11,8 +11,12 @@ namespace MaterialDesignThemes.Wpf
11
11
[ TemplateVisualState ( GroupName = TemplateAllDrawersGroupName , Name = TemplateAllDrawersAnyOpenStateName ) ]
12
12
[ TemplateVisualState ( GroupName = TemplateLeftDrawerGroupName , Name = TemplateLeftClosedStateName ) ]
13
13
[ TemplateVisualState ( GroupName = TemplateLeftDrawerGroupName , Name = TemplateLeftOpenStateName ) ]
14
+ [ TemplateVisualState ( GroupName = TemplateTopDrawerGroupName , Name = TemplateTopClosedStateName ) ]
15
+ [ TemplateVisualState ( GroupName = TemplateTopDrawerGroupName , Name = TemplateTopOpenStateName ) ]
14
16
[ TemplateVisualState ( GroupName = TemplateRightDrawerGroupName , Name = TemplateRightClosedStateName ) ]
15
17
[ TemplateVisualState ( GroupName = TemplateRightDrawerGroupName , Name = TemplateRightOpenStateName ) ]
18
+ [ TemplateVisualState ( GroupName = TemplateBottomDrawerGroupName , Name = TemplateBottomClosedStateName ) ]
19
+ [ TemplateVisualState ( GroupName = TemplateBottomDrawerGroupName , Name = TemplateBottomOpenStateName ) ]
16
20
[ TemplatePart ( Name = TemplateContentCoverPartName , Type = typeof ( FrameworkElement ) ) ]
17
21
public class DrawerHost : ContentControl
18
22
{
@@ -22,9 +26,15 @@ public class DrawerHost : ContentControl
22
26
public const string TemplateLeftDrawerGroupName = "LeftDrawer" ;
23
27
public const string TemplateLeftClosedStateName = "LeftDrawerClosed" ;
24
28
public const string TemplateLeftOpenStateName = "LeftDrawerOpen" ;
29
+ public const string TemplateTopDrawerGroupName = "TopDrawer" ;
30
+ public const string TemplateTopClosedStateName = "TopDrawerClosed" ;
31
+ public const string TemplateTopOpenStateName = "TopDrawerOpen" ;
25
32
public const string TemplateRightDrawerGroupName = "RightDrawer" ;
26
33
public const string TemplateRightClosedStateName = "RightDrawerClosed" ;
27
34
public const string TemplateRightOpenStateName = "RightDrawerOpen" ;
35
+ public const string TemplateBottomDrawerGroupName = "BottomDrawer" ;
36
+ public const string TemplateBottomClosedStateName = "BottomDrawerClosed" ;
37
+ public const string TemplateBottomOpenStateName = "BottomDrawerOpen" ;
28
38
29
39
public const string TemplateContentCoverPartName = "PART_ContentCover" ;
30
40
@@ -44,6 +54,60 @@ public DrawerHost()
44
54
CommandBindings . Add ( new CommandBinding ( CloseDrawerCommand , CloseDrawerHandler ) ) ;
45
55
}
46
56
57
+ public static readonly DependencyProperty TopDrawerContentProperty = DependencyProperty . Register (
58
+ nameof ( TopDrawerContent ) , typeof ( object ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( object ) ) ) ;
59
+
60
+ public object TopDrawerContent
61
+ {
62
+ get { return ( object ) GetValue ( TopDrawerContentProperty ) ; }
63
+ set { SetValue ( TopDrawerContentProperty , value ) ; }
64
+ }
65
+
66
+ public static readonly DependencyProperty TopDrawerContentTemplateProperty = DependencyProperty . Register (
67
+ nameof ( TopDrawerContentTemplate ) , typeof ( DataTemplate ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( DataTemplate ) ) ) ;
68
+
69
+ public DataTemplate TopDrawerContentTemplate
70
+ {
71
+ get { return ( DataTemplate ) GetValue ( TopDrawerContentTemplateProperty ) ; }
72
+ set { SetValue ( TopDrawerContentTemplateProperty , value ) ; }
73
+ }
74
+
75
+ public static readonly DependencyProperty TopDrawerContentTemplateSelectorProperty = DependencyProperty . Register (
76
+ nameof ( TopDrawerContentTemplateSelector ) , typeof ( DataTemplateSelector ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( DataTemplateSelector ) ) ) ;
77
+
78
+ public DataTemplateSelector TopDrawerContentTemplateSelector
79
+ {
80
+ get { return ( DataTemplateSelector ) GetValue ( TopDrawerContentTemplateSelectorProperty ) ; }
81
+ set { SetValue ( TopDrawerContentTemplateSelectorProperty , value ) ; }
82
+ }
83
+
84
+ public static readonly DependencyProperty TopDrawerContentStringFormatProperty = DependencyProperty . Register (
85
+ nameof ( TopDrawerContentStringFormat ) , typeof ( string ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( string ) ) ) ;
86
+
87
+ public string TopDrawerContentStringFormat
88
+ {
89
+ get { return ( string ) GetValue ( TopDrawerContentStringFormatProperty ) ; }
90
+ set { SetValue ( TopDrawerContentStringFormatProperty , value ) ; }
91
+ }
92
+
93
+ public static readonly DependencyProperty TopDrawerBackgroundProperty = DependencyProperty . Register (
94
+ nameof ( TopDrawerBackground ) , typeof ( Brush ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( Brush ) ) ) ;
95
+
96
+ public Brush TopDrawerBackground
97
+ {
98
+ get { return ( Brush ) GetValue ( TopDrawerBackgroundProperty ) ; }
99
+ set { SetValue ( TopDrawerBackgroundProperty , value ) ; }
100
+ }
101
+
102
+ public static readonly DependencyProperty IsTopDrawerOpenProperty = DependencyProperty . Register (
103
+ nameof ( IsTopDrawerOpen ) , typeof ( bool ) , typeof ( DrawerHost ) , new FrameworkPropertyMetadata ( default ( bool ) , FrameworkPropertyMetadataOptions . BindsTwoWayByDefault , IsDrawerOpenPropertyChangedCallback ) ) ;
104
+
105
+ public bool IsTopDrawerOpen
106
+ {
107
+ get { return ( bool ) GetValue ( IsTopDrawerOpenProperty ) ; }
108
+ set { SetValue ( IsTopDrawerOpenProperty , value ) ; }
109
+ }
110
+
47
111
public static readonly DependencyProperty LeftDrawerContentProperty = DependencyProperty . Register (
48
112
nameof ( LeftDrawerContent ) , typeof ( object ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( object ) ) ) ;
49
113
@@ -90,7 +154,7 @@ public Brush LeftDrawerBackground
90
154
}
91
155
92
156
public static readonly DependencyProperty IsLeftDrawerOpenProperty = DependencyProperty . Register (
93
- nameof ( IsLeftDrawerOpen ) , typeof ( bool ) , typeof ( DrawerHost ) , new FrameworkPropertyMetadata ( default ( bool ) , FrameworkPropertyMetadataOptions . BindsTwoWayByDefault , IsLeftDrawerOpenPropertyChangedCallback ) ) ;
157
+ nameof ( IsLeftDrawerOpen ) , typeof ( bool ) , typeof ( DrawerHost ) , new FrameworkPropertyMetadata ( default ( bool ) , FrameworkPropertyMetadataOptions . BindsTwoWayByDefault , IsDrawerOpenPropertyChangedCallback ) ) ;
94
158
95
159
public bool IsLeftDrawerOpen
96
160
{
@@ -144,14 +208,68 @@ public Brush RightDrawerBackground
144
208
}
145
209
146
210
public static readonly DependencyProperty IsRightDrawerOpenProperty = DependencyProperty . Register (
147
- nameof ( IsRightDrawerOpen ) , typeof ( bool ) , typeof ( DrawerHost ) , new FrameworkPropertyMetadata ( default ( bool ) , FrameworkPropertyMetadataOptions . BindsTwoWayByDefault , IsRightDrawerOpenPropertyChangedCallback ) ) ;
211
+ nameof ( IsRightDrawerOpen ) , typeof ( bool ) , typeof ( DrawerHost ) , new FrameworkPropertyMetadata ( default ( bool ) , FrameworkPropertyMetadataOptions . BindsTwoWayByDefault , IsDrawerOpenPropertyChangedCallback ) ) ;
148
212
149
213
public bool IsRightDrawerOpen
150
214
{
151
215
get { return ( bool ) GetValue ( IsRightDrawerOpenProperty ) ; }
152
216
set { SetValue ( IsRightDrawerOpenProperty , value ) ; }
153
217
}
154
218
219
+ public static readonly DependencyProperty BottomDrawerContentProperty = DependencyProperty . Register (
220
+ nameof ( BottomDrawerContent ) , typeof ( object ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( object ) ) ) ;
221
+
222
+ public object BottomDrawerContent
223
+ {
224
+ get { return ( object ) GetValue ( BottomDrawerContentProperty ) ; }
225
+ set { SetValue ( BottomDrawerContentProperty , value ) ; }
226
+ }
227
+
228
+ public static readonly DependencyProperty BottomDrawerContentTemplateProperty = DependencyProperty . Register (
229
+ nameof ( BottomDrawerContentTemplate ) , typeof ( DataTemplate ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( DataTemplate ) ) ) ;
230
+
231
+ public DataTemplate BottomDrawerContentTemplate
232
+ {
233
+ get { return ( DataTemplate ) GetValue ( BottomDrawerContentTemplateProperty ) ; }
234
+ set { SetValue ( BottomDrawerContentTemplateProperty , value ) ; }
235
+ }
236
+
237
+ public static readonly DependencyProperty BottomDrawerContentTemplateSelectorProperty = DependencyProperty . Register (
238
+ nameof ( BottomDrawerContentTemplateSelector ) , typeof ( DataTemplateSelector ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( DataTemplateSelector ) ) ) ;
239
+
240
+ public DataTemplateSelector BottomDrawerContentTemplateSelector
241
+ {
242
+ get { return ( DataTemplateSelector ) GetValue ( BottomDrawerContentTemplateSelectorProperty ) ; }
243
+ set { SetValue ( BottomDrawerContentTemplateSelectorProperty , value ) ; }
244
+ }
245
+
246
+ public static readonly DependencyProperty BottomDrawerContentStringFormatProperty = DependencyProperty . Register (
247
+ nameof ( BottomDrawerContentStringFormat ) , typeof ( string ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( string ) ) ) ;
248
+
249
+ public string BottomDrawerContentStringFormat
250
+ {
251
+ get { return ( string ) GetValue ( BottomDrawerContentStringFormatProperty ) ; }
252
+ set { SetValue ( BottomDrawerContentStringFormatProperty , value ) ; }
253
+ }
254
+
255
+ public static readonly DependencyProperty BottomDrawerBackgroundProperty = DependencyProperty . Register (
256
+ nameof ( BottomDrawerBackground ) , typeof ( Brush ) , typeof ( DrawerHost ) , new PropertyMetadata ( default ( Brush ) ) ) ;
257
+
258
+ public Brush BottomDrawerBackground
259
+ {
260
+ get { return ( Brush ) GetValue ( BottomDrawerBackgroundProperty ) ; }
261
+ set { SetValue ( BottomDrawerBackgroundProperty , value ) ; }
262
+ }
263
+
264
+ public static readonly DependencyProperty IsBottomDrawerOpenProperty = DependencyProperty . Register (
265
+ nameof ( IsBottomDrawerOpen ) , typeof ( bool ) , typeof ( DrawerHost ) , new FrameworkPropertyMetadata ( default ( bool ) , FrameworkPropertyMetadataOptions . BindsTwoWayByDefault , IsDrawerOpenPropertyChangedCallback ) ) ;
266
+
267
+ public bool IsBottomDrawerOpen
268
+ {
269
+ get { return ( bool ) GetValue ( IsBottomDrawerOpenProperty ) ; }
270
+ set { SetValue ( IsBottomDrawerOpenProperty , value ) ; }
271
+ }
272
+
155
273
public override void OnApplyTemplate ( )
156
274
{
157
275
if ( _templateContentCoverElement != null )
@@ -170,30 +288,33 @@ private void TemplateContentCoverElementOnPreviewMouseLeftButtonUp(object sender
170
288
{
171
289
SetCurrentValue ( IsLeftDrawerOpenProperty , false ) ;
172
290
SetCurrentValue ( IsRightDrawerOpenProperty , false ) ;
291
+ SetCurrentValue ( IsTopDrawerOpenProperty , false ) ;
292
+ SetCurrentValue ( IsBottomDrawerOpenProperty , false ) ;
173
293
}
174
294
175
295
private void UpdateVisualStates ( bool ? useTransitions = null )
176
296
{
177
- var anyOpen = IsLeftDrawerOpen || IsRightDrawerOpen ;
297
+ var anyOpen = IsTopDrawerOpen || IsLeftDrawerOpen || IsBottomDrawerOpen || IsRightDrawerOpen ;
178
298
179
299
VisualStateManager . GoToState ( this ,
180
300
! anyOpen ? TemplateAllDrawersAllClosedStateName : TemplateAllDrawersAnyOpenStateName , useTransitions . HasValue ? useTransitions . Value : ! TransitionAssist . GetDisableTransitions ( this ) ) ;
181
301
182
302
VisualStateManager . GoToState ( this ,
183
303
IsLeftDrawerOpen ? TemplateLeftOpenStateName : TemplateLeftClosedStateName , useTransitions . HasValue ? useTransitions . Value : ! TransitionAssist . GetDisableTransitions ( this ) ) ;
184
304
305
+ VisualStateManager . GoToState ( this ,
306
+ IsTopDrawerOpen ? TemplateTopOpenStateName : TemplateTopClosedStateName , useTransitions . HasValue ? useTransitions . Value : ! TransitionAssist . GetDisableTransitions ( this ) ) ;
307
+
185
308
VisualStateManager . GoToState ( this ,
186
309
IsRightDrawerOpen ? TemplateRightOpenStateName : TemplateRightClosedStateName , useTransitions . HasValue ? useTransitions . Value : ! TransitionAssist . GetDisableTransitions ( this ) ) ;
187
- }
188
310
189
- private static void IsLeftDrawerOpenPropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
190
- {
191
- ( ( DrawerHost ) dependencyObject ) . UpdateVisualStates ( ) ;
311
+ VisualStateManager . GoToState ( this ,
312
+ IsBottomDrawerOpen ? TemplateBottomOpenStateName : TemplateBottomClosedStateName , useTransitions . HasValue ? useTransitions . Value : ! TransitionAssist . GetDisableTransitions ( this ) ) ;
192
313
}
193
314
194
- private static void IsRightDrawerOpenPropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
315
+ private static void IsDrawerOpenPropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
195
316
{
196
- ( ( DrawerHost ) dependencyObject ) . UpdateVisualStates ( ) ;
317
+ ( ( DrawerHost ) dependencyObject ) . UpdateVisualStates ( ) ;
197
318
}
198
319
199
320
private void CloseDrawerHandler ( object sender , ExecutedRoutedEventArgs executedRoutedEventArgs )
@@ -224,11 +345,13 @@ private void SetOpenFlag(ExecutedRoutedEventArgs executedRoutedEventArgs, bool v
224
345
SetCurrentValue ( IsLeftDrawerOpenProperty , value ) ;
225
346
break ;
226
347
case Dock . Top :
348
+ SetCurrentValue ( IsTopDrawerOpenProperty , value ) ;
227
349
break ;
228
350
case Dock . Right :
229
351
SetCurrentValue ( IsRightDrawerOpenProperty , value ) ;
230
352
break ;
231
353
case Dock . Bottom :
354
+ SetCurrentValue ( IsBottomDrawerOpenProperty , value ) ;
232
355
break ;
233
356
default :
234
357
throw new ArgumentOutOfRangeException ( ) ;
@@ -237,7 +360,9 @@ private void SetOpenFlag(ExecutedRoutedEventArgs executedRoutedEventArgs, bool v
237
360
else
238
361
{
239
362
SetCurrentValue ( IsLeftDrawerOpenProperty , value ) ;
363
+ SetCurrentValue ( IsTopDrawerOpenProperty , value ) ;
240
364
SetCurrentValue ( IsRightDrawerOpenProperty , value ) ;
365
+ SetCurrentValue ( IsBottomDrawerOpenProperty , value ) ;
241
366
}
242
367
}
243
368
}
0 commit comments