-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
MetroWindow.cs
1532 lines (1330 loc) · 71.4 KB
/
MetroWindow.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using ControlzEx.Behaviors;
using ControlzEx.Native;
using ControlzEx.Standard;
using JetBrains.Annotations;
using MahApps.Metro.Behaviors;
using MahApps.Metro.Controls.Dialogs;
using Microsoft.Xaml.Behaviors;
namespace MahApps.Metro.Controls
{
/// <summary>
/// An extended, metrofied Window class.
/// </summary>
[TemplatePart(Name = PART_Icon, Type = typeof(UIElement))]
[TemplatePart(Name = PART_TitleBar, Type = typeof(UIElement))]
[TemplatePart(Name = PART_WindowTitleBackground, Type = typeof(UIElement))]
[TemplatePart(Name = PART_WindowTitleThumb, Type = typeof(Thumb))]
[TemplatePart(Name = PART_FlyoutModalDragMoveThumb, Type = typeof(Thumb))]
[TemplatePart(Name = PART_LeftWindowCommands, Type = typeof(WindowCommands))]
[TemplatePart(Name = PART_RightWindowCommands, Type = typeof(WindowCommands))]
[TemplatePart(Name = PART_WindowButtonCommands, Type = typeof(WindowButtonCommands))]
[TemplatePart(Name = PART_OverlayBox, Type = typeof(Grid))]
[TemplatePart(Name = PART_MetroActiveDialogContainer, Type = typeof(Grid))]
[TemplatePart(Name = PART_MetroInactiveDialogsContainer, Type = typeof(Grid))]
[TemplatePart(Name = PART_FlyoutModal, Type = typeof(Rectangle))]
public class MetroWindow : Window
{
private const string PART_Icon = "PART_Icon";
private const string PART_TitleBar = "PART_TitleBar";
private const string PART_WindowTitleBackground = "PART_WindowTitleBackground";
private const string PART_WindowTitleThumb = "PART_WindowTitleThumb";
private const string PART_FlyoutModalDragMoveThumb = "PART_FlyoutModalDragMoveThumb";
private const string PART_LeftWindowCommands = "PART_LeftWindowCommands";
private const string PART_RightWindowCommands = "PART_RightWindowCommands";
private const string PART_WindowButtonCommands = "PART_WindowButtonCommands";
private const string PART_OverlayBox = "PART_OverlayBox";
private const string PART_MetroActiveDialogContainer = "PART_MetroActiveDialogContainer";
private const string PART_MetroInactiveDialogsContainer = "PART_MetroInactiveDialogsContainer";
private const string PART_FlyoutModal = "PART_FlyoutModal";
private const string PART_Content = "PART_Content";
public static readonly DependencyProperty ShowIconOnTitleBarProperty = DependencyProperty.Register("ShowIconOnTitleBar", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true, OnShowIconOnTitleBarPropertyChangedCallback));
public static readonly DependencyProperty IconEdgeModeProperty = DependencyProperty.Register("IconEdgeMode", typeof(EdgeMode), typeof(MetroWindow), new PropertyMetadata(EdgeMode.Aliased));
public static readonly DependencyProperty IconBitmapScalingModeProperty = DependencyProperty.Register("IconBitmapScalingMode", typeof(BitmapScalingMode), typeof(MetroWindow), new PropertyMetadata(BitmapScalingMode.HighQuality));
public static readonly DependencyProperty IconScalingModeProperty = DependencyProperty.Register("IconScalingMode", typeof(MultiFrameImageMode), typeof(MetroWindow), new FrameworkPropertyMetadata(MultiFrameImageMode.ScaleDownLargerFrame, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty ShowTitleBarProperty = DependencyProperty.Register("ShowTitleBar", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true, OnShowTitleBarPropertyChangedCallback, OnShowTitleBarCoerceValueCallback));
public static readonly DependencyProperty ShowDialogsOverTitleBarProperty = DependencyProperty.Register("ShowDialogsOverTitleBar", typeof(bool), typeof(MetroWindow), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyPropertyKey IsAnyDialogOpenPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsAnyDialogOpen), typeof(bool), typeof(MetroWindow), new PropertyMetadata(false));
/// <summary>
/// Identifies the <see cref="IsAnyDialogOpen"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsAnyDialogOpenProperty = IsAnyDialogOpenPropertyKey.DependencyProperty;
public static readonly DependencyProperty ShowMinButtonProperty = DependencyProperty.Register("ShowMinButton", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty ShowMaxRestoreButtonProperty = DependencyProperty.Register("ShowMaxRestoreButton", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty ShowCloseButtonProperty = DependencyProperty.Register("ShowCloseButton", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty IsMinButtonEnabledProperty = DependencyProperty.Register("IsMinButtonEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty IsMaxRestoreButtonEnabledProperty = DependencyProperty.Register("IsMaxRestoreButtonEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty IsCloseButtonEnabledProperty = DependencyProperty.Register("IsCloseButtonEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyPropertyKey IsCloseButtonEnabledWithDialogPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsCloseButtonEnabledWithDialog), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
/// <summary>
/// Identifies the <see cref="IsCloseButtonEnabledWithDialog"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsCloseButtonEnabledWithDialogProperty = IsCloseButtonEnabledWithDialogPropertyKey.DependencyProperty;
public static readonly DependencyProperty ShowSystemMenuProperty = DependencyProperty.Register("ShowSystemMenu", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty ShowSystemMenuOnRightClickProperty = DependencyProperty.Register("ShowSystemMenuOnRightClick", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty TitleBarHeightProperty = DependencyProperty.Register("TitleBarHeight", typeof(int), typeof(MetroWindow), new PropertyMetadata(30, TitleBarHeightPropertyChangedCallback));
public static readonly DependencyProperty TitleCharacterCasingProperty = DependencyProperty.Register("TitleCharacterCasing", typeof(CharacterCasing), typeof(MetroWindow), new FrameworkPropertyMetadata(CharacterCasing.Upper, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure), value => CharacterCasing.Normal <= (CharacterCasing)value && (CharacterCasing)value <= CharacterCasing.Upper);
public static readonly DependencyProperty TitleAlignmentProperty = DependencyProperty.Register("TitleAlignment", typeof(HorizontalAlignment), typeof(MetroWindow), new PropertyMetadata(HorizontalAlignment.Stretch, OnTitleAlignmentChanged));
public static readonly DependencyProperty SaveWindowPositionProperty = DependencyProperty.Register("SaveWindowPosition", typeof(bool), typeof(MetroWindow), new PropertyMetadata(false));
public static readonly DependencyProperty WindowPlacementSettingsProperty = DependencyProperty.Register("WindowPlacementSettings", typeof(IWindowPlacementSettings), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty TitleForegroundProperty = DependencyProperty.Register("TitleForeground", typeof(Brush), typeof(MetroWindow));
public static readonly DependencyProperty FlyoutsProperty = DependencyProperty.Register("Flyouts", typeof(FlyoutsControl), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));
public static readonly DependencyProperty WindowTransitionsEnabledProperty = DependencyProperty.Register("WindowTransitionsEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
public static readonly DependencyProperty MetroDialogOptionsProperty = DependencyProperty.Register("MetroDialogOptions", typeof(MetroDialogSettings), typeof(MetroWindow), new PropertyMetadata(default(MetroDialogSettings)));
public static readonly DependencyProperty WindowTitleBrushProperty = DependencyProperty.Register("WindowTitleBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Transparent));
public static readonly DependencyProperty NonActiveWindowTitleBrushProperty = DependencyProperty.Register("NonActiveWindowTitleBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Gray));
public static readonly DependencyProperty NonActiveBorderBrushProperty = DependencyProperty.Register("NonActiveBorderBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Gray));
public static readonly DependencyProperty GlowBrushProperty = DependencyProperty.Register("GlowBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty NonActiveGlowBrushProperty = DependencyProperty.Register("NonActiveGlowBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty OverlayBrushProperty = DependencyProperty.Register("OverlayBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty OverlayOpacityProperty = DependencyProperty.Register("OverlayOpacity", typeof(double), typeof(MetroWindow), new PropertyMetadata(0.7d));
public static readonly DependencyProperty FlyoutOverlayBrushProperty = DependencyProperty.Register("FlyoutOverlayBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null));
/// <summary>
/// Identifies the <see cref="OverlayFadeIn"/> dependency property.
/// </summary>
public static readonly DependencyProperty OverlayFadeInProperty = DependencyProperty.Register("OverlayFadeIn", typeof(Storyboard), typeof(MetroWindow), new PropertyMetadata(default(Storyboard)));
/// <summary>
/// Identifies the <see cref="OverlayFadeOut"/> dependency property.
/// </summary>
public static readonly DependencyProperty OverlayFadeOutProperty = DependencyProperty.Register("OverlayFadeOut", typeof(Storyboard), typeof(MetroWindow), new PropertyMetadata(default(Storyboard)));
public static readonly DependencyProperty IconTemplateProperty = DependencyProperty.Register("IconTemplate", typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty TitleTemplateProperty = DependencyProperty.Register("TitleTemplate", typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null));
public static readonly DependencyProperty LeftWindowCommandsProperty = DependencyProperty.Register("LeftWindowCommands", typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));
public static readonly DependencyProperty RightWindowCommandsProperty = DependencyProperty.Register("RightWindowCommands", typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));
public static readonly DependencyProperty WindowButtonCommandsProperty = DependencyProperty.Register("WindowButtonCommands", typeof(WindowButtonCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds));
public static readonly DependencyProperty LeftWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("LeftWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Flyouts, OnShowTitleBarPropertyChangedCallback));
public static readonly DependencyProperty RightWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("RightWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Flyouts, OnShowTitleBarPropertyChangedCallback));
public static readonly DependencyProperty WindowButtonCommandsOverlayBehaviorProperty = DependencyProperty.Register("WindowButtonCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Always, OnShowTitleBarPropertyChangedCallback));
public static readonly DependencyProperty IconOverlayBehaviorProperty = DependencyProperty.Register("IconOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Never, OnShowTitleBarPropertyChangedCallback));
public static readonly DependencyProperty UseNoneWindowStyleProperty = DependencyProperty.Register("UseNoneWindowStyle", typeof(bool), typeof(MetroWindow), new PropertyMetadata(false, OnUseNoneWindowStylePropertyChangedCallback));
public static readonly DependencyProperty OverrideDefaultWindowCommandsBrushProperty = DependencyProperty.Register("OverrideDefaultWindowCommandsBrush", typeof(SolidColorBrush), typeof(MetroWindow));
public static readonly DependencyProperty IsWindowDraggableProperty = DependencyProperty.Register("IsWindowDraggable", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
FrameworkElement icon;
UIElement titleBar;
UIElement titleBarBackground;
Thumb windowTitleThumb;
Thumb flyoutModalDragMoveThumb;
private IInputElement restoreFocus;
internal ContentPresenter LeftWindowCommandsPresenter;
internal ContentPresenter RightWindowCommandsPresenter;
internal ContentPresenter WindowButtonCommandsPresenter;
internal Grid overlayBox;
internal Grid metroActiveDialogContainer;
internal Grid metroInactiveDialogContainer;
private Storyboard overlayStoryboard;
Rectangle flyoutModal;
public static readonly RoutedEvent FlyoutsStatusChangedEvent = EventManager.RegisterRoutedEvent(
"FlyoutsStatusChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MetroWindow));
// Provide CLR accessors for the event
public event RoutedEventHandler FlyoutsStatusChanged
{
add { AddHandler(FlyoutsStatusChangedEvent, value); }
remove { RemoveHandler(FlyoutsStatusChangedEvent, value); }
}
public static readonly RoutedEvent WindowTransitionCompletedEvent = EventManager.RegisterRoutedEvent("WindowTransitionCompleted", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MetroWindow));
public event RoutedEventHandler WindowTransitionCompleted
{
add { this.AddHandler(WindowTransitionCompletedEvent, value); }
remove { this.RemoveHandler(WindowTransitionCompletedEvent, value); }
}
/// <summary>
/// Allows easy handling of window commands brush. Theme is also applied based on this brush.
/// </summary>
public SolidColorBrush OverrideDefaultWindowCommandsBrush
{
get { return (SolidColorBrush)this.GetValue(OverrideDefaultWindowCommandsBrushProperty); }
set { this.SetValue(OverrideDefaultWindowCommandsBrushProperty, value); }
}
public MetroDialogSettings MetroDialogOptions
{
get { return (MetroDialogSettings)GetValue(MetroDialogOptionsProperty); }
set { SetValue(MetroDialogOptionsProperty, value); }
}
public bool IsWindowDraggable
{
get { return (bool)GetValue(IsWindowDraggableProperty); }
set { SetValue(IsWindowDraggableProperty, value); }
}
public WindowCommandsOverlayBehavior LeftWindowCommandsOverlayBehavior
{
get { return (WindowCommandsOverlayBehavior)this.GetValue(LeftWindowCommandsOverlayBehaviorProperty); }
set { SetValue(LeftWindowCommandsOverlayBehaviorProperty, value); }
}
public WindowCommandsOverlayBehavior RightWindowCommandsOverlayBehavior
{
get { return (WindowCommandsOverlayBehavior)this.GetValue(RightWindowCommandsOverlayBehaviorProperty); }
set { SetValue(RightWindowCommandsOverlayBehaviorProperty, value); }
}
public WindowCommandsOverlayBehavior WindowButtonCommandsOverlayBehavior
{
get { return (WindowCommandsOverlayBehavior)this.GetValue(WindowButtonCommandsOverlayBehaviorProperty); }
set { SetValue(WindowButtonCommandsOverlayBehaviorProperty, value); }
}
public WindowCommandsOverlayBehavior IconOverlayBehavior
{
get { return (WindowCommandsOverlayBehavior)this.GetValue(IconOverlayBehaviorProperty); }
set { SetValue(IconOverlayBehaviorProperty, value); }
}
/// <summary>
/// Gets/sets whether the window's entrance transition animation is enabled.
/// </summary>
public bool WindowTransitionsEnabled
{
get { return (bool)this.GetValue(WindowTransitionsEnabledProperty); }
set { SetValue(WindowTransitionsEnabledProperty, value); }
}
/// <summary>
/// Gets/sets the FlyoutsControl that hosts the window's flyouts.
/// </summary>
public FlyoutsControl Flyouts
{
get { return (FlyoutsControl)GetValue(FlyoutsProperty); }
set { SetValue(FlyoutsProperty, value); }
}
/// <summary>
/// Gets/sets the icon content template to show a custom icon.
/// </summary>
public DataTemplate IconTemplate
{
get { return (DataTemplate)GetValue(IconTemplateProperty); }
set { SetValue(IconTemplateProperty, value); }
}
/// <summary>
/// Gets/sets the title content template to show a custom title.
/// </summary>
public DataTemplate TitleTemplate
{
get { return (DataTemplate)GetValue(TitleTemplateProperty); }
set { SetValue(TitleTemplateProperty, value); }
}
/// <summary>
/// Gets/sets the left window commands that hosts the user commands.
/// </summary>
public WindowCommands LeftWindowCommands
{
get { return (WindowCommands)GetValue(LeftWindowCommandsProperty); }
set { SetValue(LeftWindowCommandsProperty, value); }
}
/// <summary>
/// Gets/sets the right window commands that hosts the user commands.
/// </summary>
public WindowCommands RightWindowCommands
{
get { return (WindowCommands)GetValue(RightWindowCommandsProperty); }
set { SetValue(RightWindowCommandsProperty, value); }
}
/// <summary>
/// Gets/sets the window button commands that hosts the min/max/close commands.
/// </summary>
public WindowButtonCommands WindowButtonCommands
{
get { return (WindowButtonCommands)GetValue(WindowButtonCommandsProperty); }
set { SetValue(WindowButtonCommandsProperty, value); }
}
/// <summary>
/// Defines if the Taskbar should be ignored when maximizing a Window.
/// This only works with WindowStyle = None.
/// </summary>
public bool IgnoreTaskbarOnMaximize
{
get { return (bool)this.GetValue(IgnoreTaskbarOnMaximizeProperty); }
set { SetValue(IgnoreTaskbarOnMaximizeProperty, value); }
}
/// <summary>
/// Identifies the <see cref="IgnoreTaskbarOnMaximize"/> dependency property.
/// </summary>
public static readonly DependencyProperty IgnoreTaskbarOnMaximizeProperty = DependencyProperty.Register(nameof(IgnoreTaskbarOnMaximize), typeof(bool), typeof(MetroWindow), new PropertyMetadata(false));
/// <summary>
/// Gets or sets resize border thickness. This enables animation, styling, binding, etc...
/// </summary>
public Thickness ResizeBorderThickness
{
get { return (Thickness)this.GetValue(ResizeBorderThicknessProperty); }
set { this.SetValue(ResizeBorderThicknessProperty, value); }
}
/// <summary>
/// <see cref="DependencyProperty"/> for <see cref="ResizeBorderThickness"/>.
/// </summary>
public static readonly DependencyProperty ResizeBorderThicknessProperty = DependencyProperty.Register(nameof(ResizeBorderThickness), typeof(Thickness), typeof(MetroWindow), new PropertyMetadata(new Thickness(6D)));
/// <summary>
/// Gets/sets if the border thickness value should be kept on maximize
/// if the MaxHeight/MaxWidth of the window is less than the monitor resolution.
/// </summary>
public bool KeepBorderOnMaximize
{
get { return (bool)this.GetValue(KeepBorderOnMaximizeProperty); }
set { this.SetValue(KeepBorderOnMaximizeProperty, value); }
}
/// <summary>
/// <see cref="DependencyProperty"/> for <see cref="KeepBorderOnMaximize"/>.
/// </summary>
public static readonly DependencyProperty KeepBorderOnMaximizeProperty = DependencyProperty.Register(nameof(KeepBorderOnMaximize), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true));
/// <summary>
/// Gets or sets wether the resizing of the window should be tried in a way that does not cause flicker/jitter, especially when resizing from the left side.
/// </summary>
/// <remarks>
/// Please note that setting this to <c>true</c> may cause resize lag and black areas appearing on some systems.
/// </remarks>
public bool TryToBeFlickerFree
{
get { return (bool)this.GetValue(TryToBeFlickerFreeProperty); }
set { this.SetValue(TryToBeFlickerFreeProperty, value); }
}
/// <summary>
/// <see cref="DependencyProperty"/> for <see cref="TryToBeFlickerFree"/>.
/// </summary>
public static readonly DependencyProperty TryToBeFlickerFreeProperty = DependencyProperty.Register(nameof(TryToBeFlickerFree), typeof(bool), typeof(MetroWindow), new PropertyMetadata(false));
/// <summary>
/// Gets/sets the brush used for the titlebar's foreground.
/// </summary>
public Brush TitleForeground
{
get { return (Brush)GetValue(TitleForegroundProperty); }
set { SetValue(TitleForegroundProperty, value); }
}
/// <summary>
/// Gets/sets whether the window will save it's position between loads.
/// </summary>
public bool SaveWindowPosition
{
get { return (bool)GetValue(SaveWindowPositionProperty); }
set { SetValue(SaveWindowPositionProperty, value); }
}
public IWindowPlacementSettings WindowPlacementSettings
{
get { return (IWindowPlacementSettings)GetValue(WindowPlacementSettingsProperty); }
set { SetValue(WindowPlacementSettingsProperty, value); }
}
/// <summary>
/// Gets the window placement settings (can be overwritten).
/// </summary>
public virtual IWindowPlacementSettings GetWindowPlacementSettings()
{
return this.WindowPlacementSettings ?? new WindowApplicationSettings(this);
}
/// <summary>
/// Get/sets whether the titlebar icon is visible or not.
/// </summary>
public bool ShowIconOnTitleBar
{
get { return (bool)GetValue(ShowIconOnTitleBarProperty); }
set { SetValue(ShowIconOnTitleBarProperty, value); }
}
private static void OnShowIconOnTitleBarPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var window = (MetroWindow)d;
if (e.NewValue != e.OldValue)
{
window.SetVisibiltyForIcon();
}
}
/// <summary>
/// Get/sets whether dialogs show over the title bar.
/// </summary>
public bool ShowDialogsOverTitleBar
{
get { return (bool)GetValue(ShowDialogsOverTitleBarProperty); }
set { SetValue(ShowDialogsOverTitleBarProperty, value); }
}
/// <summary>
/// Gets whether one or more dialogs are shown.
/// </summary>
public bool IsAnyDialogOpen
{
get { return (bool)GetValue(IsAnyDialogOpenProperty); }
private set { SetValue(IsAnyDialogOpenPropertyKey, value); }
}
/// <summary>
/// Gets/sets edge mode of the titlebar icon.
/// </summary>
public EdgeMode IconEdgeMode
{
get { return (EdgeMode)this.GetValue(IconEdgeModeProperty); }
set { SetValue(IconEdgeModeProperty, value); }
}
/// <summary>
/// Gets/sets bitmap scaling mode of the titlebar icon.
/// </summary>
public BitmapScalingMode IconBitmapScalingMode
{
get { return (BitmapScalingMode)this.GetValue(IconBitmapScalingModeProperty); }
set { SetValue(IconBitmapScalingModeProperty, value); }
}
/// <summary>
/// Gets/sets icon scaling mode of the titlebar.
/// </summary>
public MultiFrameImageMode IconScalingMode
{
get { return (MultiFrameImageMode)this.GetValue(IconScalingModeProperty); }
set { SetValue(IconScalingModeProperty, value); }
}
/// <summary>
/// Gets/sets whether the TitleBar is visible or not.
/// </summary>
public bool ShowTitleBar
{
get { return (bool)GetValue(ShowTitleBarProperty); }
set { SetValue(ShowTitleBarProperty, value); }
}
private static void OnShowTitleBarPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var window = (MetroWindow)d;
if (e.NewValue != e.OldValue)
{
window.SetVisibiltyForAllTitleElements();
}
}
private static object OnShowTitleBarCoerceValueCallback(DependencyObject d, object value)
{
// if UseNoneWindowStyle = true no title bar should be shown
if (((MetroWindow)d).UseNoneWindowStyle)
{
return false;
}
return value;
}
/// <summary>
/// Gets/sets whether the WindowStyle is None or not.
/// </summary>
public bool UseNoneWindowStyle
{
get { return (bool)GetValue(UseNoneWindowStyleProperty); }
set { SetValue(UseNoneWindowStyleProperty, value); }
}
private static void OnUseNoneWindowStylePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
if (e.NewValue != e.OldValue)
{
// if UseNoneWindowStyle = true no title bar should be shown
var useNoneWindowStyle = (bool)e.NewValue;
// UseNoneWindowStyle means no title bar, window commands or min, max, close buttons
if (useNoneWindowStyle)
{
((MetroWindow)d).SetCurrentValue(ShowTitleBarProperty, false);
}
}
}
/// <summary>
/// Gets/sets if the minimize button is visible.
/// </summary>
public bool ShowMinButton
{
get { return (bool)GetValue(ShowMinButtonProperty); }
set { SetValue(ShowMinButtonProperty, value); }
}
/// <summary>
/// Gets/sets if the Maximize/Restore button is visible.
/// </summary>
public bool ShowMaxRestoreButton
{
get { return (bool)GetValue(ShowMaxRestoreButtonProperty); }
set { SetValue(ShowMaxRestoreButtonProperty, value); }
}
/// <summary>
/// Gets/sets if the close button is visible.
/// </summary>
public bool ShowCloseButton
{
get { return (bool)GetValue(ShowCloseButtonProperty); }
set { SetValue(ShowCloseButtonProperty, value); }
}
/// <summary>
/// Gets/sets if the min button is enabled.
/// </summary>
public bool IsMinButtonEnabled
{
get { return (bool)GetValue(IsMinButtonEnabledProperty); }
set { SetValue(IsMinButtonEnabledProperty, value); }
}
/// <summary>
/// Gets/sets if the max/restore button is enabled.
/// </summary>
public bool IsMaxRestoreButtonEnabled
{
get { return (bool)GetValue(IsMaxRestoreButtonEnabledProperty); }
set { SetValue(IsMaxRestoreButtonEnabledProperty, value); }
}
/// <summary>
/// Gets/sets if the close button is enabled.
/// </summary>
public bool IsCloseButtonEnabled
{
get { return (bool)GetValue(IsCloseButtonEnabledProperty); }
set { SetValue(IsCloseButtonEnabledProperty, value); }
}
/// <summary>
/// Gets or sets whether if the close button should be enabled or not if a dialog is shown.
/// </summary>
public bool IsCloseButtonEnabledWithDialog
{
get { return (bool)GetValue(IsCloseButtonEnabledWithDialogProperty); }
private set { SetValue(IsCloseButtonEnabledWithDialogPropertyKey, value); }
}
/// <summary>
/// Gets or sets a value that indicates whether the system menu should popup with left mouse click on the window icon.
/// </summary>
public bool ShowSystemMenu
{
get { return (bool)GetValue(ShowSystemMenuProperty); }
set { SetValue(ShowSystemMenuProperty, value); }
}
/// <summary>
/// Gets or sets a value that indicates whether the system menu should popup with right mouse click if the mouse position is on title bar or on the entire window if it has no title bar (and no title bar height).
/// </summary>
public bool ShowSystemMenuOnRightClick
{
get { return (bool)GetValue(ShowSystemMenuOnRightClickProperty); }
set { SetValue(ShowSystemMenuOnRightClickProperty, value); }
}
/// <summary>
/// Gets/sets the TitleBar's height.
/// </summary>
public int TitleBarHeight
{
get { return (int)GetValue(TitleBarHeightProperty); }
set { SetValue(TitleBarHeightProperty, value); }
}
private static void TitleBarHeightPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
var window = (MetroWindow)dependencyObject;
if (e.NewValue != e.OldValue)
{
window.SetVisibiltyForAllTitleElements();
}
}
private void SetVisibiltyForIcon()
{
if (this.icon != null)
{
var isVisible = (this.IconOverlayBehavior.HasFlag(WindowCommandsOverlayBehavior.HiddenTitleBar) && !this.ShowTitleBar)
|| (this.ShowIconOnTitleBar && this.ShowTitleBar);
var iconVisibility = isVisible ? Visibility.Visible : Visibility.Collapsed;
this.icon.Visibility = iconVisibility;
}
}
private void SetVisibiltyForAllTitleElements()
{
this.SetVisibiltyForIcon();
var newVisibility = this.TitleBarHeight > 0 && this.ShowTitleBar && !this.UseNoneWindowStyle ? Visibility.Visible : Visibility.Collapsed;
this.titleBar?.SetCurrentValue(VisibilityProperty, newVisibility);
this.titleBarBackground?.SetCurrentValue(VisibilityProperty, newVisibility);
var leftWindowCommandsVisibility = this.LeftWindowCommandsOverlayBehavior.HasFlag(WindowCommandsOverlayBehavior.HiddenTitleBar) && !this.UseNoneWindowStyle ? Visibility.Visible : newVisibility;
this.LeftWindowCommandsPresenter?.SetCurrentValue(VisibilityProperty, leftWindowCommandsVisibility);
var rightWindowCommandsVisibility = this.RightWindowCommandsOverlayBehavior.HasFlag(WindowCommandsOverlayBehavior.HiddenTitleBar) && !this.UseNoneWindowStyle ? Visibility.Visible : newVisibility;
this.RightWindowCommandsPresenter?.SetCurrentValue(VisibilityProperty, rightWindowCommandsVisibility);
var windowButtonCommandsVisibility = this.WindowButtonCommandsOverlayBehavior.HasFlag(WindowCommandsOverlayBehavior.HiddenTitleBar) ? Visibility.Visible : newVisibility;
this.WindowButtonCommandsPresenter?.SetCurrentValue(VisibilityProperty, windowButtonCommandsVisibility);
this.SetWindowEvents();
}
/// <summary>
/// Character casing of the title
/// </summary>
public CharacterCasing TitleCharacterCasing
{
get { return (CharacterCasing)GetValue(TitleCharacterCasingProperty); }
set { SetValue(TitleCharacterCasingProperty, value); }
}
/// <summary>
/// Gets/sets the title horizontal alignment.
/// </summary>
public HorizontalAlignment TitleAlignment
{
get { return (HorizontalAlignment)GetValue(TitleAlignmentProperty); }
set { SetValue(TitleAlignmentProperty, value); }
}
private static void OnTitleAlignmentChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
var window = dependencyObject as MetroWindow;
if (window != null)
{
window.SizeChanged -= window.MetroWindow_SizeChanged;
if (e.NewValue is HorizontalAlignment && (HorizontalAlignment)e.NewValue == HorizontalAlignment.Center)
{
window.SizeChanged += window.MetroWindow_SizeChanged;
}
}
}
/// <summary>
/// Gets/sets the brush used for the Window's title bar.
/// </summary>
public Brush WindowTitleBrush
{
get { return (Brush)GetValue(WindowTitleBrushProperty); }
set { SetValue(WindowTitleBrushProperty, value); }
}
/// <summary>
/// Gets/sets the brush used for the Window's glow.
/// </summary>
public Brush GlowBrush
{
get { return (Brush)GetValue(GlowBrushProperty); }
set { SetValue(GlowBrushProperty, value); }
}
/// <summary>
/// Gets/sets the brush used for the Window's non-active glow.
/// </summary>
public Brush NonActiveGlowBrush
{
get { return (Brush)GetValue(NonActiveGlowBrushProperty); }
set { SetValue(NonActiveGlowBrushProperty, value); }
}
/// <summary>
/// Gets/sets the brush used for the Window's non-active border.
/// </summary>
public Brush NonActiveBorderBrush
{
get { return (Brush)GetValue(NonActiveBorderBrushProperty); }
set { SetValue(NonActiveBorderBrushProperty, value); }
}
/// <summary>
/// Gets/sets the brush used for the Window's non-active title bar.
/// </summary>
public Brush NonActiveWindowTitleBrush
{
get { return (Brush)GetValue(NonActiveWindowTitleBrushProperty); }
set { SetValue(NonActiveWindowTitleBrushProperty, value); }
}
/// <summary>
/// Gets/sets the brush used for the dialog overlay.
/// </summary>
public Brush OverlayBrush
{
get { return (Brush)GetValue(OverlayBrushProperty); }
set { SetValue(OverlayBrushProperty, value); }
}
/// <summary>
/// Gets/sets the opacity used for the dialog overlay.
/// </summary>
public double OverlayOpacity
{
get { return (double)GetValue(OverlayOpacityProperty); }
set { SetValue(OverlayOpacityProperty, value); }
}
/// <summary>
/// Gets or sets the brush used for the Flyouts overlay.
/// </summary>
public Brush FlyoutOverlayBrush
{
get { return (Brush)GetValue(FlyoutOverlayBrushProperty); }
set { SetValue(FlyoutOverlayBrushProperty, value); }
}
/// <summary>
/// Gets or sets the overlay fade in storyboard.
/// </summary>
public Storyboard OverlayFadeIn
{
get { return (Storyboard)GetValue(OverlayFadeInProperty); }
set { SetValue(OverlayFadeInProperty, value); }
}
/// <summary>
/// Gets or sets the overlay fade out storyboard.
/// </summary>
public Storyboard OverlayFadeOut
{
get { return (Storyboard)GetValue(OverlayFadeOutProperty); }
set { SetValue(OverlayFadeOutProperty, value); }
}
private bool CanUseOverlayFadingStoryboard(Storyboard sb, out DoubleAnimation animation)
{
animation = null;
if (null == sb)
{
return false;
}
sb.Dispatcher.VerifyAccess();
animation = sb.Children.OfType<DoubleAnimation>().FirstOrDefault();
if (null == animation)
{
return false;
}
return (sb.Duration.HasTimeSpan && sb.Duration.TimeSpan.Ticks > 0)
|| (sb.AccelerationRatio > 0)
|| (sb.DecelerationRatio > 0)
|| (animation.Duration.HasTimeSpan && animation.Duration.TimeSpan.Ticks > 0)
|| animation.AccelerationRatio > 0
|| animation.DecelerationRatio > 0;
}
/// <summary>
/// Begins to show the MetroWindow's overlay effect.
/// </summary>
/// <returns>A task representing the process.</returns>
public System.Threading.Tasks.Task ShowOverlayAsync()
{
if (overlayBox == null) throw new InvalidOperationException("OverlayBox can not be founded in this MetroWindow's template. Are you calling this before the window has loaded?");
var tcs = new System.Threading.Tasks.TaskCompletionSource<object>();
if (IsOverlayVisible() && overlayStoryboard == null)
{
//No Task.FromResult in .NET 4.
tcs.SetResult(null);
return tcs.Task;
}
Dispatcher.VerifyAccess();
var sb = OverlayFadeIn?.Clone();
overlayStoryboard = sb;
DoubleAnimation animation;
if (CanUseOverlayFadingStoryboard(sb, out animation))
{
this.overlayBox.SetCurrentValue(VisibilityProperty, Visibility.Visible);
animation.To = this.OverlayOpacity;
EventHandler completionHandler = null;
completionHandler = (sender, args) =>
{
sb.Completed -= completionHandler;
if (overlayStoryboard == sb)
{
overlayStoryboard = null;
}
tcs.TrySetResult(null);
};
sb.Completed += completionHandler;
overlayBox.BeginStoryboard(sb);
}
else
{
ShowOverlay();
tcs.TrySetResult(null);
}
return tcs.Task;
}
/// <summary>
/// Begins to hide the MetroWindow's overlay effect.
/// </summary>
/// <returns>A task representing the process.</returns>
public System.Threading.Tasks.Task HideOverlayAsync()
{
if (overlayBox == null) throw new InvalidOperationException("OverlayBox can not be founded in this MetroWindow's template. Are you calling this before the window has loaded?");
var tcs = new System.Threading.Tasks.TaskCompletionSource<object>();
if (overlayBox.Visibility == Visibility.Visible && overlayBox.Opacity <= 0.0)
{
//No Task.FromResult in .NET 4.
this.overlayBox.SetCurrentValue(VisibilityProperty, Visibility.Hidden);
tcs.SetResult(null);
return tcs.Task;
}
Dispatcher.VerifyAccess();
var sb = OverlayFadeOut?.Clone();
overlayStoryboard = sb;
DoubleAnimation animation;
if (CanUseOverlayFadingStoryboard(sb, out animation))
{
animation.To = 0d;
EventHandler completionHandler = null;
completionHandler = (sender, args) =>
{
sb.Completed -= completionHandler;
if (overlayStoryboard == sb)
{
this.overlayBox.SetCurrentValue(VisibilityProperty, Visibility.Hidden);
overlayStoryboard = null;
}
tcs.TrySetResult(null);
};
sb.Completed += completionHandler;
overlayBox.BeginStoryboard(sb);
}
else
{
HideOverlay();
tcs.TrySetResult(null);
}
return tcs.Task;
}
public bool IsOverlayVisible()
{
if (overlayBox == null) throw new InvalidOperationException("OverlayBox can not be founded in this MetroWindow's template. Are you calling this before the window has loaded?");
return overlayBox.Visibility == Visibility.Visible && overlayBox.Opacity >= this.OverlayOpacity;
}
public void ShowOverlay()
{
this.overlayBox.SetCurrentValue(VisibilityProperty, Visibility.Visible);
overlayBox.SetCurrentValue(Grid.OpacityProperty, this.OverlayOpacity);
}
public void HideOverlay()
{
overlayBox.SetCurrentValue(Grid.OpacityProperty, 0d);
this.overlayBox.SetCurrentValue(VisibilityProperty, Visibility.Hidden);
}
/// <summary>
/// Stores the given element, or the last focused element via FocusManager, for restoring the focus after closing a dialog.
/// </summary>
/// <param name="thisElement">The element which will be focused again.</param>
public void StoreFocus([CanBeNull] IInputElement thisElement = null)
{
Dispatcher.BeginInvoke(new Action(() =>
{
restoreFocus = thisElement ?? (this.restoreFocus ?? FocusManager.GetFocusedElement(this));
}));
}
internal void RestoreFocus()
{
if (restoreFocus != null)
{
Dispatcher.BeginInvoke(new Action(() =>
{
Keyboard.Focus(restoreFocus);
restoreFocus = null;
}));
}
}
/// <summary>
/// Clears the stored element which would get the focus after closing a dialog.
/// </summary>
public void ResetStoredFocus()
{
restoreFocus = null;
}
static MetroWindow()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MetroWindow), new FrameworkPropertyMetadata(typeof(MetroWindow)));
}
/// <summary>
/// Initializes a new instance of the MahApps.Metro.Controls.MetroWindow class.
/// </summary>
public MetroWindow()
{
this.SetCurrentValue(MetroDialogOptionsProperty, new MetroDialogSettings());
// BorderlessWindowBehavior initialization has to occur in constructor. Otherwise the load event is fired early and performance of the window is degraded.
this.InitializeWindowChromeBehavior();
this.InitializeSettingsBehavior();
this.InitializeGlowWindowBehavior();
DataContextChanged += MetroWindow_DataContextChanged;
Loaded += this.MetroWindow_Loaded;
}
private void MetroWindow_Loaded(object sender, RoutedEventArgs e)
{
if (this.Flyouts == null)
{
this.Flyouts = new FlyoutsControl();
}
this.ResetAllWindowCommandsBrush();
ThemeManager.IsThemeChanged += ThemeManagerOnIsThemeChanged;
this.Unloaded += (o, args) => ThemeManager.IsThemeChanged -= ThemeManagerOnIsThemeChanged;
}
private void InitializeWindowChromeBehavior()
{
var behavior = new BorderlessWindowBehavior();
Interaction.GetBehaviors(this).Add(behavior);
}
private void InitializeGlowWindowBehavior()
{
var glowWindowBehavior = new GlowWindowBehavior();
BindingOperations.SetBinding(glowWindowBehavior, GlowWindowBehavior.ResizeBorderThicknessProperty, new Binding { Path = new PropertyPath(ResizeBorderThicknessProperty), Source = this });
BindingOperations.SetBinding(glowWindowBehavior, GlowWindowBehavior.GlowBrushProperty, new Binding { Path = new PropertyPath(GlowBrushProperty), Source = this });
BindingOperations.SetBinding(glowWindowBehavior, GlowWindowBehavior.NonActiveGlowBrushProperty, new Binding { Path = new PropertyPath(NonActiveGlowBrushProperty), Source = this });
Interaction.GetBehaviors(this).Add(glowWindowBehavior);
}
private void InitializeSettingsBehavior()
{
var behavior = new WindowsSettingBehavior();
Interaction.GetBehaviors(this).Add(behavior);
}
/// <summary>
/// Initializes various behaviors for the window.
/// For example <see cref="BorderlessWindowBehavior"/>, <see cref="WindowsSettingBehavior"/> and <see cref="GlowWindowBehavior"/>.
/// </summary>
private void InitializeBehaviors()
{
// var borderlessWindowBehavior = new BorderlessWindowBehavior();
//
// var windowsSettingBehavior = new WindowsSettingBehavior();
//
// var glowWindowBehavior = new GlowWindowBehavior();
// BindingOperations.SetBinding(glowWindowBehavior, GlowWindowBehavior.ResizeBorderThicknessProperty, new Binding { Path = new PropertyPath(ResizeBorderThicknessProperty), Source = this });
// BindingOperations.SetBinding(glowWindowBehavior, GlowWindowBehavior.GlowBrushProperty, new Binding { Path = new PropertyPath(GlowBrushProperty), Source = this });
// BindingOperations.SetBinding(glowWindowBehavior, GlowWindowBehavior.NonActiveGlowBrushProperty, new Binding { Path = new PropertyPath(NonActiveGlowBrushProperty), Source = this });
//
// var collection = new StylizedBehaviorCollection
// {
// borderlessWindowBehavior,
// windowsSettingBehavior,
// glowWindowBehavior
// };
//
// StylizedBehaviors.SetBehaviors(this, collection);
}
protected override async void OnClosing(CancelEventArgs e)
{