@@ -11,6 +11,8 @@ 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 = TemplateRightDrawerGroupName , Name = TemplateRightClosedStateName ) ]
15
+ [ TemplateVisualState ( GroupName = TemplateRightDrawerGroupName , Name = TemplateRightOpenStateName ) ]
14
16
[ TemplatePart ( Name = TemplateContentCoverPartName , Type = typeof ( FrameworkElement ) ) ]
15
17
public class DrawerHost : ContentControl
16
18
{
@@ -20,6 +22,9 @@ public class DrawerHost : ContentControl
20
22
public const string TemplateLeftDrawerGroupName = "LeftDrawer" ;
21
23
public const string TemplateLeftClosedStateName = "LeftDrawerClosed" ;
22
24
public const string TemplateLeftOpenStateName = "LeftDrawerOpen" ;
25
+ public const string TemplateRightDrawerGroupName = "RightDrawer" ;
26
+ public const string TemplateRightClosedStateName = "RightDrawerClosed" ;
27
+ public const string TemplateRightOpenStateName = "RightDrawerOpen" ;
23
28
24
29
public const string TemplateContentCoverPartName = "PART_ContentCover" ;
25
30
@@ -93,6 +98,60 @@ public bool IsLeftDrawerOpen
93
98
set { SetValue ( IsLeftDrawerOpenProperty , value ) ; }
94
99
}
95
100
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
+
96
155
public override void OnApplyTemplate ( )
97
156
{
98
157
if ( _templateContentCoverElement != null )
@@ -105,35 +164,44 @@ public override void OnApplyTemplate()
105
164
_templateContentCoverElement . PreviewMouseLeftButtonUp += TemplateContentCoverElementOnPreviewMouseLeftButtonUp ;
106
165
107
166
108
- UpdateVisualStates ( false ) ;
167
+ UpdateVisualStates ( ) ;
109
168
}
110
169
111
170
private void TemplateContentCoverElementOnPreviewMouseLeftButtonUp ( object sender , MouseButtonEventArgs mouseButtonEventArgs )
112
171
{
113
172
SetCurrentValue ( IsLeftDrawerOpenProperty , false ) ;
114
173
}
115
174
116
- private void UpdateVisualStates ( bool useTransitions )
175
+ private void UpdateVisualStates ( )
117
176
{
118
- var anyOpen = IsLeftDrawerOpen ;
177
+ var anyOpen = IsLeftDrawerOpen || IsRightDrawerOpen ;
119
178
120
179
VisualStateManager . GoToState ( this ,
121
180
! anyOpen ? TemplateAllDrawersAllClosedStateName : TemplateAllDrawersAnyOpenStateName , ! TransitionAssist . GetDisableTransitions ( this ) ) ;
122
181
123
182
VisualStateManager . GoToState ( this ,
124
183
IsLeftDrawerOpen ? TemplateLeftOpenStateName : TemplateLeftClosedStateName , ! TransitionAssist . GetDisableTransitions ( this ) ) ;
184
+
185
+ VisualStateManager . GoToState ( this ,
186
+ IsRightDrawerOpen ? TemplateRightOpenStateName : TemplateRightClosedStateName , ! TransitionAssist . GetDisableTransitions ( this ) ) ;
125
187
}
126
188
127
189
private static void IsLeftDrawerOpenPropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
128
190
{
129
- ( ( DrawerHost ) dependencyObject ) . UpdateVisualStates ( true ) ;
191
+ ( ( DrawerHost ) dependencyObject ) . UpdateVisualStates ( ) ;
130
192
}
131
193
194
+ private static void IsRightDrawerOpenPropertyChangedCallback ( DependencyObject dependencyObject , DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs )
195
+ {
196
+ ( ( DrawerHost ) dependencyObject ) . UpdateVisualStates ( ) ;
197
+ }
198
+
199
+
132
200
private void CloseDrawerHandler ( object sender , ExecutedRoutedEventArgs executedRoutedEventArgs )
133
201
{
134
202
if ( executedRoutedEventArgs . Handled ) return ;
135
203
136
- SetCurrentValue ( IsLeftDrawerOpenProperty , false ) ;
204
+ SetOpenFlag ( executedRoutedEventArgs , false ) ;
137
205
138
206
executedRoutedEventArgs . Handled = true ;
139
207
}
@@ -142,9 +210,36 @@ private void OpenDrawerHandler(object sender, ExecutedRoutedEventArgs executedRo
142
210
{
143
211
if ( executedRoutedEventArgs . Handled ) return ;
144
212
145
- SetCurrentValue ( IsLeftDrawerOpenProperty , true ) ;
213
+ SetOpenFlag ( executedRoutedEventArgs , true ) ;
146
214
147
215
executedRoutedEventArgs . Handled = true ;
148
216
}
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
+ }
149
244
}
150
245
}
0 commit comments