@@ -27,14 +27,14 @@ public sealed partial class SideDrawer : UserControl
27
27
private static readonly DependencyProperty SecondaryPanelWidthProperty =
28
28
DependencyProperty . Register ( nameof ( SecondaryPanelWidth ) , typeof ( float ) , typeof ( Shadow ) , new PropertyMetadata ( 228f , OnPanelWidthPropertyChanged ) ) ;
29
29
30
- private InteractionTracker _tracker ;
31
- private VisualInteractionSource _interactionSource ;
32
- private Compositor _compositor ;
30
+ private readonly InteractionTracker _tracker ;
31
+ private readonly VisualInteractionSource _interactionSource ;
32
+ private readonly Compositor _compositor ;
33
33
34
- private Visual _mainVisual ;
35
- private Visual _leftVisual ;
36
- private Visual _left2Visual ;
37
- private Visual _rightVisual ;
34
+ private readonly Visual _mainVisual ;
35
+ private readonly Visual _leftVisual ;
36
+ private readonly Visual _left2Visual ;
37
+ private readonly Visual _rightVisual ;
38
38
39
39
// These animations represent the position of the panes relative to the tracker position.
40
40
private ExpressionAnimation ? _mainTranslateAnimation ;
@@ -46,9 +46,9 @@ public sealed partial class SideDrawer : UserControl
46
46
// The start point is where the panel rests when the left panel is open
47
47
// The mid point is where the panel rests when the panels are closed
48
48
// The end point is where the panel rests when the right panel is open
49
- private InteractionTrackerInertiaRestingValue _startPoint ;
50
- private InteractionTrackerInertiaRestingValue _midPoint ;
51
- private InteractionTrackerInertiaRestingValue _endPoint ;
49
+ private readonly InteractionTrackerInertiaRestingValue _startPoint ;
50
+ private readonly InteractionTrackerInertiaRestingValue _midPoint ;
51
+ private readonly InteractionTrackerInertiaRestingValue _endPoint ;
52
52
53
53
/// <summary>
54
54
/// Inializes a new instance of the <see cref="SideDrawer"/> class.
@@ -137,21 +137,6 @@ public object RightContent
137
137
set => RightContentControl . Content = value ;
138
138
}
139
139
140
- /// <summary>
141
- /// Gets or sets the minimum size where the <see cref="SideDrawer"/> will enter the <see cref="SideDrawerSize.Medium"/> size UI.
142
- /// </summary>
143
- public double MediumMinSize { get ; set ; } = 600 ;
144
-
145
- /// <summary>
146
- /// Gets or sets the minimum size where the <see cref="SideDrawer"/> will enter the <see cref="SideDrawerSize.Large"/> size UI.
147
- /// </summary>
148
- public double LargeMinSize { get ; set ; } = 1100 ;
149
-
150
- /// <summary>
151
- /// Gets or sets the minimum size where the <see cref="SideDrawer"/> will enter the <see cref="SideDrawerSize.ExtraLarge"/> size UI.
152
- /// </summary>
153
- public double ExtraLargeMinSize { get ; set ; } = 1400 ;
154
-
155
140
/// <summary>
156
141
/// Gets or sets the width of the secondary panels.
157
142
/// </summary>
@@ -194,7 +179,10 @@ public float PrimaryPanelWidth
194
179
/// </remarks>
195
180
public bool IsRightOpen => FlowDirection == FlowDirection . LeftToRight ? _tracker . Position . X > 0 : _tracker . Position . X < 0 ;
196
181
197
- private SideDrawerSize Size
182
+ /// <summary>
183
+ /// Gets or sets the behavioral size of the side drawer control.
184
+ /// </summary>
185
+ public SideDrawerSize Size
198
186
{
199
187
get => ( SideDrawerSize ) GetValue ( SizeProperty ) ;
200
188
set => SetValue ( SizeProperty , value ) ;
@@ -303,6 +291,11 @@ private void SetupComposition()
303
291
_rightVisual . StartAnimation ( TranslationX , _rightTranslateAnimation ) ;
304
292
305
293
SetSnapPoints ( - TotalPanelWidth , 0 , SecondaryPanelWidth ) ;
294
+
295
+ // Invoke size update
296
+ var cache = Size ;
297
+ Size = SideDrawerSize . Small ;
298
+ Size = cache ;
306
299
}
307
300
308
301
private void SetupAnimations ( )
@@ -340,26 +333,6 @@ private void OnPointerPressed(object sender, PointerRoutedEventArgs e)
340
333
}
341
334
}
342
335
343
- private void OnSizeChanged ( object sender , SizeChangedEventArgs e )
344
- {
345
- SideDrawerSize size = SideDrawerSize . ExtraLarge ;
346
- double width = e . NewSize . Width ;
347
- if ( width < MediumMinSize )
348
- {
349
- size = SideDrawerSize . Small ;
350
- }
351
- else if ( width < LargeMinSize )
352
- {
353
- size = SideDrawerSize . Medium ;
354
- }
355
- else if ( width < ExtraLargeMinSize )
356
- {
357
- size = SideDrawerSize . Large ;
358
- }
359
-
360
- Size = size ;
361
- }
362
-
363
336
private async void SetSizeSmall ( SideDrawerSize previous )
364
337
{
365
338
main . Margin = new Thickness ( 0 , 0 , 0 , 0 ) ;
@@ -545,28 +518,21 @@ private static void OnSizePropertyChanged(DependencyObject d, DependencyProperty
545
518
SideDrawerSize newSize = ( SideDrawerSize ) args . NewValue ;
546
519
SideDrawerSize oldSize = ( SideDrawerSize ) args . OldValue ;
547
520
548
- if ( newSize == oldSize )
549
- {
550
- return ;
551
- }
521
+ if ( ! sideDrawer . IsLoaded ) return ;
522
+ if ( newSize == oldSize ) return ;
552
523
553
524
sideDrawer . TrackerTranslate ( 0 ) ;
554
525
555
- switch ( newSize )
526
+ Action < SideDrawerSize > adjustment = newSize switch
556
527
{
557
- case SideDrawerSize . Small :
558
- sideDrawer . SetSizeSmall ( oldSize ) ;
559
- break ;
560
- case SideDrawerSize . Medium :
561
- sideDrawer . SetSizeMedium ( oldSize ) ;
562
- break ;
563
- case SideDrawerSize . Large :
564
- sideDrawer . SetSizeLarge ( oldSize ) ;
565
- break ;
566
- case SideDrawerSize . ExtraLarge :
567
- sideDrawer . SetSizeExtraLarge ( oldSize ) ;
568
- break ;
569
- }
528
+ SideDrawerSize . Small => sideDrawer . SetSizeSmall ,
529
+ SideDrawerSize . Medium => sideDrawer . SetSizeMedium ,
530
+ SideDrawerSize . Large => sideDrawer . SetSizeLarge ,
531
+ SideDrawerSize . ExtraLarge => sideDrawer . SetSizeExtraLarge ,
532
+ _ => sideDrawer . SetSizeSmall ,
533
+ } ;
534
+
535
+ adjustment ? . Invoke ( oldSize ) ;
570
536
571
537
// Adjust tracker bounds for right to left flow direction
572
538
if ( sideDrawer . FlowDirection == FlowDirection . RightToLeft )
0 commit comments