From 7faefb2be7df33c4db5fea8ccddf6a64b29a8bb0 Mon Sep 17 00:00:00 2001 From: punker76 Date: Sun, 28 Jun 2020 22:31:15 +0200 Subject: [PATCH 1/2] Add BooleanBoxes static class to improve dependency properties performance This performance tip is an good old one taken from this site https://xstatic2.wordpress.com/2011/10/21/tip-improving-boolean-dependency-properties-performance/ --- src/MahApps.Metro/ValueBoxes/BooleanBoxes.cs | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/MahApps.Metro/ValueBoxes/BooleanBoxes.cs diff --git a/src/MahApps.Metro/ValueBoxes/BooleanBoxes.cs b/src/MahApps.Metro/ValueBoxes/BooleanBoxes.cs new file mode 100644 index 0000000000..bd4583d7a8 --- /dev/null +++ b/src/MahApps.Metro/ValueBoxes/BooleanBoxes.cs @@ -0,0 +1,25 @@ +namespace MahApps.Metro.ValueBoxes +{ + /// + /// Helps boxing Boolean values. + /// + public static class BooleanBoxes + { + /// + /// Gets a boxed representation for Boolean's "true" value. + /// + public static readonly object TrueBox = true; + + /// + /// Gets a boxed representation for Boolean's "false" value. + /// + public static readonly object FalseBox = false; + + /// + /// Returns a boxed representation for the specified Boolean value. + /// + /// The value to box. + /// + public static object Box(bool value) => value ? TrueBox : FalseBox; + } +} \ No newline at end of file From 26170da32213d34cdc860a90aeb7ca5b1a50ef3f Mon Sep 17 00:00:00 2001 From: punker76 Date: Mon, 29 Jun 2020 13:48:56 +0200 Subject: [PATCH 2/2] Use BooleanBoxes for better dependency properties performance --- .../Actions/CloseFlyoutAction.cs | 3 +- .../Actions/CommandTriggerAction.cs | 3 +- .../Behaviors/PasswordBoxBindingBehavior.cs | 11 +-- src/MahApps.Metro/Behaviors/ReloadBehavior.cs | 9 +- src/MahApps.Metro/Behaviors/TiltBehavior.cs | 5 +- src/MahApps.Metro/Controls/ClipBorder.cs | 5 +- .../Controls/ContentControlEx.cs | 5 +- .../Controls/CustomValidationPopup.cs | 27 +++--- .../Controls/Dialogs/LoginDialog.xaml.cs | 9 +- .../Controls/Dialogs/ProgressDialog.xaml.cs | 5 +- src/MahApps.Metro/Controls/DropDownButton.cs | 7 +- src/MahApps.Metro/Controls/FlipView.cs | 17 ++-- src/MahApps.Metro/Controls/Flyout.cs | 37 +++++---- src/MahApps.Metro/Controls/FlyoutsControl.cs | 5 +- .../HamburgerMenu/HamburgerMenu.Properties.cs | 17 ++-- .../MenuItems/HamburgerMenuItem.cs | 7 +- .../MenuItems/HamburgerMenuItemBase.cs | 5 +- .../Controls/Helper/ControlsHelper.cs | 9 +- .../Controls/Helper/DataGridHelper.cs | 7 +- .../Controls/Helper/ScrollViewerHelper.cs | 9 +- .../Controls/Helper/TabControlHelper.cs | 5 +- .../Controls/Helper/TextBoxHelper.cs | 43 +++++----- .../Controls/Helper/ValidationHelper.cs | 9 +- src/MahApps.Metro/Controls/HotKeyBox.cs | 5 +- .../Controls/MetroContentControl.cs | 17 ++-- src/MahApps.Metro/Controls/MetroTabControl.cs | 5 +- src/MahApps.Metro/Controls/MetroTabItem.cs | 5 +- .../Controls/MetroThumbContentControl.cs | 5 +- src/MahApps.Metro/Controls/MetroWindow.cs | 83 ++++++++++--------- src/MahApps.Metro/Controls/NumericUpDown.cs | 41 ++++----- src/MahApps.Metro/Controls/ProgressRing.cs | 11 +-- src/MahApps.Metro/Controls/RangeSlider.cs | 21 ++--- src/MahApps.Metro/Controls/SplitButton.cs | 5 +- .../Controls/SplitView/SplitView.cs | 16 ++-- src/MahApps.Metro/Controls/Tile.cs | 5 +- .../Controls/TimePicker/DateTimePicker.cs | 3 +- .../Controls/TimePicker/TimePickerBase.cs | 25 +++--- src/MahApps.Metro/Controls/ToggleSwitch.cs | 11 +-- .../Controls/TransitioningContentControl.cs | 9 +- src/MahApps.Metro/Controls/WindowCommands.cs | 9 +- .../Controls/WindowCommandsItem.cs | 5 +- 41 files changed, 291 insertions(+), 249 deletions(-) diff --git a/src/MahApps.Metro/Actions/CloseFlyoutAction.cs b/src/MahApps.Metro/Actions/CloseFlyoutAction.cs index 1a1c7490bc..0fbfa37001 100644 --- a/src/MahApps.Metro/Actions/CloseFlyoutAction.cs +++ b/src/MahApps.Metro/Actions/CloseFlyoutAction.cs @@ -1,4 +1,5 @@ using MahApps.Metro.Controls; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Actions { @@ -26,7 +27,7 @@ protected override void Invoke(object parameter) } else { - this.AssociatedFlyout?.SetCurrentValue(Flyout.IsOpenProperty, false); + this.AssociatedFlyout?.SetCurrentValue(Flyout.IsOpenProperty, BooleanBoxes.FalseBox); } } diff --git a/src/MahApps.Metro/Actions/CommandTriggerAction.cs b/src/MahApps.Metro/Actions/CommandTriggerAction.cs index f66f12dd96..a142543b84 100644 --- a/src/MahApps.Metro/Actions/CommandTriggerAction.cs +++ b/src/MahApps.Metro/Actions/CommandTriggerAction.cs @@ -1,6 +1,7 @@ using System; using System.Windows; using System.Windows.Input; +using MahApps.Metro.ValueBoxes; using Microsoft.Xaml.Behaviors; namespace MahApps.Metro.Actions @@ -117,7 +118,7 @@ private void EnableDisableElement() } var command = this.Command; - this.AssociatedObject.SetCurrentValue(UIElement.IsEnabledProperty, command == null || command.CanExecute(this.GetCommandParameter())); + this.AssociatedObject.SetCurrentValue(UIElement.IsEnabledProperty, BooleanBoxes.Box(command == null || command.CanExecute(this.GetCommandParameter()))); } private void OnCommandCanExecuteChanged(object sender, EventArgs e) diff --git a/src/MahApps.Metro/Behaviors/PasswordBoxBindingBehavior.cs b/src/MahApps.Metro/Behaviors/PasswordBoxBindingBehavior.cs index 33ce847c91..915fab3d73 100644 --- a/src/MahApps.Metro/Behaviors/PasswordBoxBindingBehavior.cs +++ b/src/MahApps.Metro/Behaviors/PasswordBoxBindingBehavior.cs @@ -12,6 +12,7 @@ using System.Windows.Controls; using System.Windows.Documents; using MahApps.Metro.Controls; +using MahApps.Metro.ValueBoxes; using Microsoft.Xaml.Behaviors; namespace MahApps.Metro.Behaviors @@ -159,16 +160,16 @@ private static readonly DependencyProperty IsChangingProperty = DependencyProperty.RegisterAttached("IsChanging", typeof(bool), typeof(PasswordBoxBindingBehavior), - new UIPropertyMetadata(false)); + new UIPropertyMetadata(BooleanBoxes.FalseBox)); - private static bool GetIsChanging(DependencyObject obj) + private static bool GetIsChanging(UIElement element) { - return (bool)obj.GetValue(IsChangingProperty); + return (bool)element.GetValue(IsChangingProperty); } - private static void SetIsChanging(DependencyObject obj, bool value) + private static void SetIsChanging(UIElement element, bool value) { - obj.SetValue(IsChangingProperty, value); + element.SetValue(IsChangingProperty, BooleanBoxes.Box(value)); } private static readonly DependencyProperty SelectionProperty diff --git a/src/MahApps.Metro/Behaviors/ReloadBehavior.cs b/src/MahApps.Metro/Behaviors/ReloadBehavior.cs index 5e620afbb0..bdcb11eb6a 100644 --- a/src/MahApps.Metro/Behaviors/ReloadBehavior.cs +++ b/src/MahApps.Metro/Behaviors/ReloadBehavior.cs @@ -2,6 +2,7 @@ using System.Windows; using System.Windows.Controls; using MahApps.Metro.Controls; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Behaviors { @@ -17,7 +18,7 @@ public static readonly DependencyProperty OnDataContextChangedProperty = DependencyProperty.RegisterAttached("OnDataContextChanged", typeof(bool), typeof(ReloadBehavior), - new PropertyMetadata(OnOnDataContextChanged)); + new PropertyMetadata(BooleanBoxes.FalseBox, OnOnDataContextChanged)); /// /// Helper for getting from . @@ -44,7 +45,7 @@ public static bool GetOnDataContextChanged(UIElement element) [AttachedPropertyBrowsableForType(typeof(MetroContentControl))] public static void SetOnDataContextChanged(UIElement element, bool value) { - element.SetValue(OnDataContextChangedProperty, value); + element.SetValue(OnDataContextChangedProperty, BooleanBoxes.Box(value)); } private static void OnOnDataContextChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) @@ -71,7 +72,7 @@ public static readonly DependencyProperty OnSelectedTabChangedProperty = DependencyProperty.RegisterAttached("OnSelectedTabChanged", typeof(bool), typeof(ReloadBehavior), - new PropertyMetadata(OnSelectedTabChanged)); + new PropertyMetadata(BooleanBoxes.FalseBox, OnSelectedTabChanged)); /// /// Helper for getting from . @@ -100,7 +101,7 @@ public static bool GetOnSelectedTabChanged(UIElement element) [AttachedPropertyBrowsableForType(typeof(TransitioningContentControl))] public static void SetOnSelectedTabChanged(UIElement element, bool value) { - element.SetValue(OnSelectedTabChangedProperty, value); + element.SetValue(OnSelectedTabChangedProperty, BooleanBoxes.Box(value)); } private static void OnSelectedTabChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) diff --git a/src/MahApps.Metro/Behaviors/TiltBehavior.cs b/src/MahApps.Metro/Behaviors/TiltBehavior.cs index fe8be0ca18..c70b44c1b3 100644 --- a/src/MahApps.Metro/Behaviors/TiltBehavior.cs +++ b/src/MahApps.Metro/Behaviors/TiltBehavior.cs @@ -6,6 +6,7 @@ using System.Windows.Media; using ControlzEx.Theming; using MahApps.Metro.Controls; +using MahApps.Metro.ValueBoxes; using Microsoft.Xaml.Behaviors; namespace MahApps.Metro.Behaviors @@ -17,12 +18,12 @@ public static readonly DependencyProperty KeepDraggingProperty = DependencyProperty.Register(nameof(KeepDragging), typeof(bool), typeof(TiltBehavior), - new PropertyMetadata(true)); + new PropertyMetadata(BooleanBoxes.TrueBox)); public bool KeepDragging { get => (bool)this.GetValue(KeepDraggingProperty); - set => this.SetValue(KeepDraggingProperty, value); + set => this.SetValue(KeepDraggingProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. diff --git a/src/MahApps.Metro/Controls/ClipBorder.cs b/src/MahApps.Metro/Controls/ClipBorder.cs index 46ce5bd284..b1340d686e 100644 --- a/src/MahApps.Metro/Controls/ClipBorder.cs +++ b/src/MahApps.Metro/Controls/ClipBorder.cs @@ -30,6 +30,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -220,7 +221,7 @@ public Brush Background /// public static readonly DependencyProperty OptimizeClipRenderingProperty = DependencyProperty.Register(nameof(OptimizeClipRendering), typeof(bool), typeof(ClipBorder), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsRender)); /// /// Gets or sets the OptimizeClipRendering property. This dependency property @@ -235,7 +236,7 @@ public Brush Background public bool OptimizeClipRendering { get { return (bool)GetValue(OptimizeClipRenderingProperty); } - set { SetValue(OptimizeClipRenderingProperty, value); } + set { SetValue(OptimizeClipRenderingProperty, BooleanBoxes.Box(value)); } } #endregion diff --git a/src/MahApps.Metro/Controls/ContentControlEx.cs b/src/MahApps.Metro/Controls/ContentControlEx.cs index 783dd7be12..2b56c57840 100644 --- a/src/MahApps.Metro/Controls/ContentControlEx.cs +++ b/src/MahApps.Metro/Controls/ContentControlEx.cs @@ -1,5 +1,6 @@ using System.Windows; using System.Windows.Controls; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -27,7 +28,7 @@ public static readonly DependencyProperty RecognizesAccessKeyProperty = DependencyProperty.Register(nameof(RecognizesAccessKey), typeof(bool), typeof(ContentControlEx), - new FrameworkPropertyMetadata(false)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); /// /// Determine if the inner ContentPresenter should use AccessText in its style @@ -35,7 +36,7 @@ public static readonly DependencyProperty RecognizesAccessKeyProperty public bool RecognizesAccessKey { get => (bool)this.GetValue(RecognizesAccessKeyProperty); - set => this.SetValue(RecognizesAccessKeyProperty, value); + set => this.SetValue(RecognizesAccessKeyProperty, BooleanBoxes.Box(value)); } static ContentControlEx() diff --git a/src/MahApps.Metro/Controls/CustomValidationPopup.cs b/src/MahApps.Metro/Controls/CustomValidationPopup.cs index a72317020e..c1f137e28d 100644 --- a/src/MahApps.Metro/Controls/CustomValidationPopup.cs +++ b/src/MahApps.Metro/Controls/CustomValidationPopup.cs @@ -6,6 +6,7 @@ using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Interop; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -29,7 +30,7 @@ public static readonly DependencyProperty CloseOnMouseLeftButtonDownProperty = DependencyProperty.Register(nameof(CloseOnMouseLeftButtonDown), typeof(bool), typeof(CustomValidationPopup), - new PropertyMetadata(true)); + new PropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets or sets whether if the popup can be closed by left mouse button down. @@ -37,7 +38,7 @@ public static readonly DependencyProperty CloseOnMouseLeftButtonDownProperty public bool CloseOnMouseLeftButtonDown { get => (bool)this.GetValue(CloseOnMouseLeftButtonDownProperty); - set => this.SetValue(CloseOnMouseLeftButtonDownProperty, value); + set => this.SetValue(CloseOnMouseLeftButtonDownProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -45,7 +46,7 @@ public static readonly DependencyProperty ShowValidationErrorOnMouseOverProperty = DependencyProperty.RegisterAttached(nameof(ShowValidationErrorOnMouseOver), typeof(bool), typeof(CustomValidationPopup), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets whether the validation error text will be shown when hovering the validation triangle. @@ -53,7 +54,7 @@ public static readonly DependencyProperty ShowValidationErrorOnMouseOverProperty public bool ShowValidationErrorOnMouseOver { get => (bool)this.GetValue(ShowValidationErrorOnMouseOverProperty); - set => this.SetValue(ShowValidationErrorOnMouseOverProperty, value); + set => this.SetValue(ShowValidationErrorOnMouseOverProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -77,7 +78,7 @@ public static readonly DependencyPropertyKey CanShowPropertyKey = DependencyProperty.RegisterReadOnly(nameof(CanShow), typeof(bool), typeof(CustomValidationPopup), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// Identifies the dependency property. public static readonly DependencyProperty CanShowProperty = CanShowPropertyKey.DependencyProperty; @@ -88,7 +89,7 @@ public static readonly DependencyPropertyKey CanShowPropertyKey public bool CanShow { get => (bool)this.GetValue(CanShowProperty); - protected set => this.SetValue(CanShowPropertyKey, value); + protected set => this.SetValue(CanShowPropertyKey, BooleanBoxes.Box(value)); } public CustomValidationPopup() @@ -101,14 +102,14 @@ protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e) { if (this.CloseOnMouseLeftButtonDown) { - this.SetCurrentValue(IsOpenProperty, false); + this.SetCurrentValue(IsOpenProperty, BooleanBoxes.FalseBox); } else { var adornedElement = this.AdornedElement; if (adornedElement != null && ValidationHelper.GetCloseOnMouseLeftButtonDown(adornedElement)) { - this.SetCurrentValue(IsOpenProperty, false); + this.SetCurrentValue(IsOpenProperty, BooleanBoxes.FalseBox); } else { @@ -219,7 +220,7 @@ private void Flyout_OpeningFinished(object sender, RoutedEventArgs e) var adornedElement = this.AdornedElement; var isOpen = Validation.GetHasError(adornedElement) && adornedElement.IsKeyboardFocusWithin; - this.SetCurrentValue(IsOpenProperty, isOpen); + this.SetCurrentValue(IsOpenProperty, BooleanBoxes.Box(isOpen)); this.SetValue(CanShowPropertyKey, true); } @@ -248,7 +249,7 @@ private void OnTransitionCompleted(object sender, RoutedEventArgs e) var adornedElement = this.AdornedElement; var isOpen = Validation.GetHasError(adornedElement) && adornedElement.IsKeyboardFocusWithin; - this.SetCurrentValue(IsOpenProperty, isOpen); + this.SetCurrentValue(IsOpenProperty, BooleanBoxes.Box(isOpen)); this.SetValue(CanShowPropertyKey, true); } @@ -263,11 +264,11 @@ private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) { var adornedElement = this.AdornedElement; var isOpen = Validation.GetHasError(adornedElement) && adornedElement.IsKeyboardFocusWithin; - this.SetCurrentValue(IsOpenProperty, isOpen); + this.SetCurrentValue(IsOpenProperty, BooleanBoxes.Box(isOpen)); } else { - this.SetCurrentValue(IsOpenProperty, false); + this.SetCurrentValue(IsOpenProperty, BooleanBoxes.FalseBox); } } } @@ -362,7 +363,7 @@ private void OnHostWindowStateChanged(object sender, EventArgs e) if (adornedElement != null) { this.PopupAnimation = PopupAnimation.None; - this.SetCurrentValue(IsOpenProperty, false); + this.SetCurrentValue(IsOpenProperty, BooleanBoxes.FalseBox); var errorTemplate = adornedElement.GetValue(Validation.ErrorTemplateProperty); adornedElement.SetValue(Validation.ErrorTemplateProperty, null); adornedElement.SetValue(Validation.ErrorTemplateProperty, errorTemplate); diff --git a/src/MahApps.Metro/Controls/Dialogs/LoginDialog.xaml.cs b/src/MahApps.Metro/Controls/Dialogs/LoginDialog.xaml.cs index 4693f74f64..0b4a5daa8c 100644 --- a/src/MahApps.Metro/Controls/Dialogs/LoginDialog.xaml.cs +++ b/src/MahApps.Metro/Controls/Dialogs/LoginDialog.xaml.cs @@ -3,6 +3,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls.Dialogs { @@ -90,12 +91,12 @@ public Visibility NegativeButtonButtonVisibility } /// Identifies the dependency property. - public static readonly DependencyProperty ShouldHideUsernameProperty = DependencyProperty.Register(nameof(ShouldHideUsername), typeof(bool), typeof(LoginDialog), new PropertyMetadata(false)); + public static readonly DependencyProperty ShouldHideUsernameProperty = DependencyProperty.Register(nameof(ShouldHideUsername), typeof(bool), typeof(LoginDialog), new PropertyMetadata(BooleanBoxes.FalseBox)); public bool ShouldHideUsername { get { return (bool)this.GetValue(ShouldHideUsernameProperty); } - set { this.SetValue(ShouldHideUsernameProperty, value); } + set { this.SetValue(ShouldHideUsernameProperty, BooleanBoxes.Box(value)); } } /// Identifies the dependency property. @@ -117,12 +118,12 @@ public string RememberCheckBoxText } /// Identifies the dependency property. - public static readonly DependencyProperty RememberCheckBoxCheckedProperty = DependencyProperty.Register(nameof(RememberCheckBoxChecked), typeof(bool), typeof(LoginDialog), new PropertyMetadata(false)); + public static readonly DependencyProperty RememberCheckBoxCheckedProperty = DependencyProperty.Register(nameof(RememberCheckBoxChecked), typeof(bool), typeof(LoginDialog), new PropertyMetadata(BooleanBoxes.FalseBox)); public bool RememberCheckBoxChecked { get { return (bool)this.GetValue(RememberCheckBoxCheckedProperty); } - set { this.SetValue(RememberCheckBoxCheckedProperty, value); } + set { this.SetValue(RememberCheckBoxCheckedProperty, BooleanBoxes.Box(value)); } } internal LoginDialog() diff --git a/src/MahApps.Metro/Controls/Dialogs/ProgressDialog.xaml.cs b/src/MahApps.Metro/Controls/Dialogs/ProgressDialog.xaml.cs index 2aed23f297..ffdf6887ac 100644 --- a/src/MahApps.Metro/Controls/Dialogs/ProgressDialog.xaml.cs +++ b/src/MahApps.Metro/Controls/Dialogs/ProgressDialog.xaml.cs @@ -1,6 +1,7 @@ using System.Threading; using System.Windows; using System.Windows.Media; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls.Dialogs { @@ -19,12 +20,12 @@ public string Message } /// Identifies the dependency property. - public static readonly DependencyProperty IsCancelableProperty = DependencyProperty.Register(nameof(IsCancelable), typeof(bool), typeof(ProgressDialog), new PropertyMetadata(default(bool), (s, e) => { ((ProgressDialog)s).PART_NegativeButton.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Hidden; })); + public static readonly DependencyProperty IsCancelableProperty = DependencyProperty.Register(nameof(IsCancelable), typeof(bool), typeof(ProgressDialog), new PropertyMetadata(BooleanBoxes.FalseBox, (s, e) => { ((ProgressDialog)s).PART_NegativeButton.Visibility = (bool)e.NewValue ? Visibility.Visible : Visibility.Hidden; })); public bool IsCancelable { get { return (bool)this.GetValue(IsCancelableProperty); } - set { this.SetValue(IsCancelableProperty, value); } + set { this.SetValue(IsCancelableProperty, BooleanBoxes.Box(value)); } } /// Identifies the dependency property. diff --git a/src/MahApps.Metro/Controls/DropDownButton.cs b/src/MahApps.Metro/Controls/DropDownButton.cs index 8e26697912..d7246c7307 100644 --- a/src/MahApps.Metro/Controls/DropDownButton.cs +++ b/src/MahApps.Metro/Controls/DropDownButton.cs @@ -6,6 +6,7 @@ using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -34,7 +35,7 @@ public static readonly DependencyProperty IsExpandedProperty = DependencyProperty.Register(nameof(IsExpanded), typeof(bool), typeof(DropDownButton), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsExpandedPropertyChangedCallback)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsExpandedPropertyChangedCallback)); private static void OnIsExpandedPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) { @@ -58,7 +59,7 @@ protected virtual void SetContextMenuPlacementTarget(ContextMenu contextMenu) public bool IsExpanded { get => (bool)this.GetValue(IsExpandedProperty); - set => this.SetValue(IsExpandedProperty, value); + set => this.SetValue(IsExpandedProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -411,7 +412,7 @@ private void ButtonClick(object sender, RoutedEventArgs e) if (this.contextMenu?.HasItems == true) { - this.SetCurrentValue(IsExpandedProperty, true); + this.SetCurrentValue(IsExpandedProperty, BooleanBoxes.TrueBox); } e.RoutedEvent = ClickEvent; diff --git a/src/MahApps.Metro/Controls/FlipView.cs b/src/MahApps.Metro/Controls/FlipView.cs index 87214c4ee6..88f069699c 100644 --- a/src/MahApps.Metro/Controls/FlipView.cs +++ b/src/MahApps.Metro/Controls/FlipView.cs @@ -8,6 +8,7 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -40,7 +41,7 @@ public Brush MouseHoverBorderBrush } /// Identifies the dependency property. - public static readonly DependencyProperty MouseHoverBorderEnabledProperty = DependencyProperty.Register(nameof(MouseHoverBorderEnabled), typeof(bool), typeof(FlipView), new PropertyMetadata(true)); + public static readonly DependencyProperty MouseHoverBorderEnabledProperty = DependencyProperty.Register(nameof(MouseHoverBorderEnabled), typeof(bool), typeof(FlipView), new PropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets or sets a value indicating whether the border for mouse over effect is enabled or not. @@ -48,7 +49,7 @@ public Brush MouseHoverBorderBrush public bool MouseHoverBorderEnabled { get => (bool)this.GetValue(MouseHoverBorderEnabledProperty); - set => this.SetValue(MouseHoverBorderEnabledProperty, value); + set => this.SetValue(MouseHoverBorderEnabledProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -64,7 +65,7 @@ public Thickness MouseHoverBorderThickness } /// Identifies the dependency property. - public static readonly DependencyProperty CircularNavigationProperty = DependencyProperty.Register(nameof(CircularNavigation), typeof(bool), typeof(FlipView), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender, (d, e) => ((FlipView)d).DetectControlButtonsStatus())); + public static readonly DependencyProperty CircularNavigationProperty = DependencyProperty.Register(nameof(CircularNavigation), typeof(bool), typeof(FlipView), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsRender, (d, e) => ((FlipView)d).DetectControlButtonsStatus())); /// /// Gets or sets a value indicating whether the navigation is circular, so you get the first after last and the last before first. @@ -72,7 +73,7 @@ public Thickness MouseHoverBorderThickness public bool CircularNavigation { get => (bool)this.GetValue(CircularNavigationProperty); - set => this.SetValue(CircularNavigationProperty, value); + set => this.SetValue(CircularNavigationProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -151,7 +152,7 @@ public TransitionType DownTransition } /// Identifies the dependency property. - public static readonly DependencyProperty IsBannerEnabledProperty = DependencyProperty.Register(nameof(IsBannerEnabled), typeof(bool), typeof(FlipView), new UIPropertyMetadata(true, OnIsBannerEnabledPropertyChangedCallback)); + public static readonly DependencyProperty IsBannerEnabledProperty = DependencyProperty.Register(nameof(IsBannerEnabled), typeof(bool), typeof(FlipView), new UIPropertyMetadata(BooleanBoxes.TrueBox, OnIsBannerEnabledPropertyChangedCallback)); /// /// Gets or sets whether the banner is visible or not. @@ -159,7 +160,7 @@ public TransitionType DownTransition public bool IsBannerEnabled { get => (bool)this.GetValue(IsBannerEnabledProperty); - set => this.SetValue(IsBannerEnabledProperty, value); + set => this.SetValue(IsBannerEnabledProperty, BooleanBoxes.Box(value)); } private static void OnIsBannerEnabledPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -195,7 +196,7 @@ void ChangeFlipViewBannerVisibility() } /// Identifies the dependency property. - public static readonly DependencyProperty IsNavigationEnabledProperty = DependencyProperty.Register(nameof(IsNavigationEnabled), typeof(bool), typeof(FlipView), new PropertyMetadata(true, (d, e) => ((FlipView)d).DetectControlButtonsStatus())); + public static readonly DependencyProperty IsNavigationEnabledProperty = DependencyProperty.Register(nameof(IsNavigationEnabled), typeof(bool), typeof(FlipView), new PropertyMetadata(BooleanBoxes.TrueBox, (d, e) => ((FlipView)d).DetectControlButtonsStatus())); /// /// Gets or sets whether the navigation button are visible or not. @@ -203,7 +204,7 @@ void ChangeFlipViewBannerVisibility() public bool IsNavigationEnabled { get => (bool)this.GetValue(IsNavigationEnabledProperty); - set => this.SetValue(IsNavigationEnabledProperty, value); + set => this.SetValue(IsNavigationEnabledProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. diff --git a/src/MahApps.Metro/Controls/Flyout.cs b/src/MahApps.Metro/Controls/Flyout.cs index 196eaebba3..b01390de13 100644 --- a/src/MahApps.Metro/Controls/Flyout.cs +++ b/src/MahApps.Metro/Controls/Flyout.cs @@ -9,6 +9,7 @@ using System.Windows.Threading; using ControlzEx; using ControlzEx.Theming; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -62,11 +63,11 @@ public event RoutedEventHandler ClosingFinished } public static readonly DependencyProperty PositionProperty = DependencyProperty.Register(nameof(Position), typeof(Position), typeof(Flyout), new PropertyMetadata(Position.Left, PositionChanged)); - public static readonly DependencyProperty IsPinnedProperty = DependencyProperty.Register(nameof(IsPinned), typeof(bool), typeof(Flyout), new PropertyMetadata(true)); - public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(nameof(IsOpen), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsOpenedChanged)); - public static readonly DependencyProperty AnimateOnPositionChangeProperty = DependencyProperty.Register(nameof(AnimateOnPositionChange), typeof(bool), typeof(Flyout), new PropertyMetadata(true)); - public static readonly DependencyProperty AnimateOpacityProperty = DependencyProperty.Register(nameof(AnimateOpacity), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(false, AnimateOpacityChanged)); - public static readonly DependencyProperty IsModalProperty = DependencyProperty.Register(nameof(IsModal), typeof(bool), typeof(Flyout)); + public static readonly DependencyProperty IsPinnedProperty = DependencyProperty.Register(nameof(IsPinned), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.TrueBox)); + public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register(nameof(IsOpen), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsOpenedChanged)); + public static readonly DependencyProperty AnimateOnPositionChangeProperty = DependencyProperty.Register(nameof(AnimateOnPositionChange), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.TrueBox)); + public static readonly DependencyProperty AnimateOpacityProperty = DependencyProperty.Register(nameof(AnimateOpacity), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, AnimateOpacityChanged)); + public static readonly DependencyProperty IsModalProperty = DependencyProperty.Register(nameof(IsModal), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.FalseBox)); public static readonly DependencyProperty CloseCommandProperty = DependencyProperty.RegisterAttached(nameof(CloseCommand), typeof(ICommand), typeof(Flyout), new UIPropertyMetadata(null)); public static readonly DependencyProperty CloseCommandParameterProperty = DependencyProperty.Register(nameof(CloseCommandParameter), typeof(object), typeof(Flyout), new PropertyMetadata(null)); @@ -74,12 +75,12 @@ public event RoutedEventHandler ClosingFinished public static readonly DependencyProperty ThemeProperty = DependencyProperty.Register(nameof(Theme), typeof(FlyoutTheme), typeof(Flyout), new FrameworkPropertyMetadata(FlyoutTheme.Dark, ThemeChanged)); public static readonly DependencyProperty ExternalCloseButtonProperty = DependencyProperty.Register(nameof(ExternalCloseButton), typeof(MouseButton), typeof(Flyout), new PropertyMetadata(MouseButton.Left)); public static readonly DependencyProperty CloseButtonVisibilityProperty = DependencyProperty.Register(nameof(CloseButtonVisibility), typeof(Visibility), typeof(Flyout), new FrameworkPropertyMetadata(Visibility.Visible)); - public static readonly DependencyProperty CloseButtonIsCancelProperty = DependencyProperty.Register(nameof(CloseButtonIsCancel), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(false)); + public static readonly DependencyProperty CloseButtonIsCancelProperty = DependencyProperty.Register(nameof(CloseButtonIsCancel), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.FalseBox)); public static readonly DependencyProperty TitleVisibilityProperty = DependencyProperty.Register(nameof(TitleVisibility), typeof(Visibility), typeof(Flyout), new FrameworkPropertyMetadata(Visibility.Visible)); - public static readonly DependencyProperty AreAnimationsEnabledProperty = DependencyProperty.Register(nameof(AreAnimationsEnabled), typeof(bool), typeof(Flyout), new PropertyMetadata(true)); + public static readonly DependencyProperty AreAnimationsEnabledProperty = DependencyProperty.Register(nameof(AreAnimationsEnabled), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.TrueBox)); public static readonly DependencyProperty FocusedElementProperty = DependencyProperty.Register(nameof(FocusedElement), typeof(FrameworkElement), typeof(Flyout), new UIPropertyMetadata(null)); - public static readonly DependencyProperty AllowFocusElementProperty = DependencyProperty.Register(nameof(AllowFocusElement), typeof(bool), typeof(Flyout), new PropertyMetadata(true)); - public static readonly DependencyProperty IsAutoCloseEnabledProperty = DependencyProperty.Register(nameof(IsAutoCloseEnabled), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(false, IsAutoCloseEnabledChanged)); + public static readonly DependencyProperty AllowFocusElementProperty = DependencyProperty.Register(nameof(AllowFocusElement), typeof(bool), typeof(Flyout), new PropertyMetadata(BooleanBoxes.TrueBox)); + public static readonly DependencyProperty IsAutoCloseEnabledProperty = DependencyProperty.Register(nameof(IsAutoCloseEnabled), typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, IsAutoCloseEnabledChanged)); public static readonly DependencyProperty AutoCloseIntervalProperty = DependencyProperty.Register(nameof(AutoCloseInterval), typeof(long), typeof(Flyout), new FrameworkPropertyMetadata(5000L, AutoCloseIntervalChanged)); internal PropertyChangeNotifier IsOpenPropertyChangeNotifier { get; set; } @@ -88,7 +89,7 @@ public event RoutedEventHandler ClosingFinished public bool AreAnimationsEnabled { get { return (bool)this.GetValue(AreAnimationsEnabledProperty); } - set { this.SetValue(AreAnimationsEnabledProperty, value); } + set { this.SetValue(AreAnimationsEnabledProperty, BooleanBoxes.Box(value)); } } /// @@ -115,7 +116,7 @@ public Visibility CloseButtonVisibility public bool CloseButtonIsCancel { get { return (bool)this.GetValue(CloseButtonIsCancelProperty); } - set { this.SetValue(CloseButtonIsCancelProperty, value); } + set { this.SetValue(CloseButtonIsCancelProperty, BooleanBoxes.Box(value)); } } /// @@ -143,7 +144,7 @@ public object CloseCommandParameter public bool IsOpen { get { return (bool)this.GetValue(IsOpenProperty); } - set { this.SetValue(IsOpenProperty, value); } + set { this.SetValue(IsOpenProperty, BooleanBoxes.Box(value)); } } /// @@ -152,7 +153,7 @@ public bool IsOpen public bool AnimateOnPositionChange { get { return (bool)this.GetValue(AnimateOnPositionChangeProperty); } - set { this.SetValue(AnimateOnPositionChangeProperty, value); } + set { this.SetValue(AnimateOnPositionChangeProperty, BooleanBoxes.Box(value)); } } /// @@ -161,7 +162,7 @@ public bool AnimateOnPositionChange public bool AnimateOpacity { get { return (bool)this.GetValue(AnimateOpacityProperty); } - set { this.SetValue(AnimateOpacityProperty, value); } + set { this.SetValue(AnimateOpacityProperty, BooleanBoxes.Box(value)); } } /// @@ -170,7 +171,7 @@ public bool AnimateOpacity public bool IsPinned { get { return (bool)this.GetValue(IsPinnedProperty); } - set { this.SetValue(IsPinnedProperty, value); } + set { this.SetValue(IsPinnedProperty, BooleanBoxes.Box(value)); } } /// @@ -188,7 +189,7 @@ public MouseButton ExternalCloseButton public bool IsModal { get { return (bool)this.GetValue(IsModalProperty); } - set { this.SetValue(IsModalProperty, value); } + set { this.SetValue(IsModalProperty, BooleanBoxes.Box(value)); } } /// @@ -224,7 +225,7 @@ public FrameworkElement FocusedElement public bool IsAutoCloseEnabled { get { return (bool)this.GetValue(IsAutoCloseEnabledProperty); } - set { this.SetValue(IsAutoCloseEnabledProperty, value); } + set { this.SetValue(IsAutoCloseEnabledProperty, BooleanBoxes.Box(value)); } } /// @@ -242,7 +243,7 @@ public long AutoCloseInterval public bool AllowFocusElement { get { return (bool)this.GetValue(AllowFocusElementProperty); } - set { this.SetValue(AllowFocusElementProperty, value); } + set { this.SetValue(AllowFocusElementProperty, BooleanBoxes.Box(value)); } } static Flyout() diff --git a/src/MahApps.Metro/Controls/FlyoutsControl.cs b/src/MahApps.Metro/Controls/FlyoutsControl.cs index fd4216e36f..0de5f2943f 100644 --- a/src/MahApps.Metro/Controls/FlyoutsControl.cs +++ b/src/MahApps.Metro/Controls/FlyoutsControl.cs @@ -6,6 +6,7 @@ using System.Windows.Controls; using System.Windows.Input; using ControlzEx; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -17,7 +18,7 @@ namespace MahApps.Metro.Controls public class FlyoutsControl : ItemsControl { public static readonly DependencyProperty OverrideExternalCloseButtonProperty = DependencyProperty.Register(nameof(OverrideExternalCloseButton), typeof(MouseButton?), typeof(FlyoutsControl), new PropertyMetadata(null)); - public static readonly DependencyProperty OverrideIsPinnedProperty = DependencyProperty.Register(nameof(OverrideIsPinned), typeof(bool), typeof(FlyoutsControl), new PropertyMetadata(false)); + public static readonly DependencyProperty OverrideIsPinnedProperty = DependencyProperty.Register(nameof(OverrideIsPinned), typeof(bool), typeof(FlyoutsControl), new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets/sets whether is ignored and all flyouts behave as if it was set to the value of this property. @@ -34,7 +35,7 @@ public MouseButton? OverrideExternalCloseButton public bool OverrideIsPinned { get { return (bool)GetValue(OverrideIsPinnedProperty); } - set { SetValue(OverrideIsPinnedProperty, value); } + set { SetValue(OverrideIsPinnedProperty, BooleanBoxes.Box(value)); } } static FlyoutsControl() diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs index b4ec1ce17a..cb6d6ad75d 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/HamburgerMenu.Properties.cs @@ -3,6 +3,7 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -160,7 +161,7 @@ public static readonly DependencyProperty CanResizeOpenPaneProperty = DependencyProperty.Register(nameof(CanResizeOpenPane), typeof(bool), typeof(HamburgerMenu), - new PropertyMetadata(false, OnCanResizeOpenPanePropertyChangedCallback)); + new PropertyMetadata(BooleanBoxes.FalseBox, OnCanResizeOpenPanePropertyChangedCallback)); private static void OnCanResizeOpenPanePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { @@ -176,7 +177,7 @@ private static void OnCanResizeOpenPanePropertyChangedCallback(DependencyObject public bool CanResizeOpenPane { get => (bool)this.GetValue(CanResizeOpenPaneProperty); - set => this.SetValue(CanResizeOpenPaneProperty, value); + set => this.SetValue(CanResizeOpenPaneProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -304,7 +305,7 @@ public static readonly DependencyProperty IsPaneOpenProperty = DependencyProperty.Register(nameof(IsPaneOpen), typeof(bool), typeof(HamburgerMenu), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsPaneOpenPropertyChangedCallback)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsPaneOpenPropertyChangedCallback)); private static void IsPaneOpenPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs args) { @@ -320,7 +321,7 @@ private static void IsPaneOpenPropertyChangedCallback(DependencyObject dependenc public bool IsPaneOpen { get => (bool)this.GetValue(IsPaneOpenProperty); - set => this.SetValue(IsPaneOpenProperty, value); + set => this.SetValue(IsPaneOpenProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -504,7 +505,7 @@ public static readonly DependencyProperty VerticalScrollBarOnLeftSideProperty = DependencyProperty.Register(nameof(VerticalScrollBarOnLeftSide), typeof(bool), typeof(HamburgerMenu), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets whether the ScrollBar of the HamburgerMenu is on the left side or on the right side of the menu items. @@ -512,7 +513,7 @@ public static readonly DependencyProperty VerticalScrollBarOnLeftSideProperty public bool VerticalScrollBarOnLeftSide { get => (bool)this.GetValue(VerticalScrollBarOnLeftSideProperty); - set => this.SetValue(VerticalScrollBarOnLeftSideProperty, value); + set => this.SetValue(VerticalScrollBarOnLeftSideProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -520,7 +521,7 @@ public static readonly DependencyProperty ShowSelectionIndicatorProperty = DependencyProperty.Register(nameof(ShowSelectionIndicator), typeof(bool), typeof(HamburgerMenu), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets whether a selection indicator will be shown on the HamburgerMenuItem. @@ -528,7 +529,7 @@ public static readonly DependencyProperty ShowSelectionIndicatorProperty public bool ShowSelectionIndicator { get => (bool)this.GetValue(ShowSelectionIndicatorProperty); - set => this.SetValue(ShowSelectionIndicatorProperty, value); + set => this.SetValue(ShowSelectionIndicatorProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/HamburgerMenuItem.cs b/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/HamburgerMenuItem.cs index 37f8bfbb8a..29dce6add4 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/HamburgerMenuItem.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/HamburgerMenuItem.cs @@ -1,6 +1,7 @@ using System; using System.Windows; using System.Windows.Input; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -37,7 +38,7 @@ public class HamburgerMenuItem : HamburgerMenuItemBase, IHamburgerMenuItem, ICom /// /// Identifies the dependency property. /// - public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.Register(nameof(IsEnabled), typeof(bool), typeof(HamburgerMenuItem), new PropertyMetadata(true, null, IsEnabledCoerceValueCallback)); + public static readonly DependencyProperty IsEnabledProperty = DependencyProperty.Register(nameof(IsEnabled), typeof(bool), typeof(HamburgerMenuItem), new PropertyMetadata(BooleanBoxes.TrueBox, null, IsEnabledCoerceValueCallback)); /// /// Identifies the dependency property. @@ -142,7 +143,7 @@ public bool IsEnabled set { - this.SetValue(IsEnabledProperty, value); + this.SetValue(IsEnabledProperty, BooleanBoxes.Box(value)); } } @@ -220,7 +221,7 @@ private static object IsEnabledCoerceValueCallback(DependencyObject d, object va { if (!(bool)value) { - return false; + return BooleanBoxes.FalseBox; } return ((HamburgerMenuItem)d).CanExecute; } diff --git a/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/HamburgerMenuItemBase.cs b/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/HamburgerMenuItemBase.cs index a3ff7e4a1e..6071e16301 100644 --- a/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/HamburgerMenuItemBase.cs +++ b/src/MahApps.Metro/Controls/HamburgerMenu/MenuItems/HamburgerMenuItemBase.cs @@ -1,4 +1,5 @@ using System.Windows; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -12,7 +13,7 @@ public class HamburgerMenuItemBase : Freezable, IHamburgerMenuItemBase /// /// Identifies the dependency property. /// - public static readonly DependencyProperty IsVisibleProperty = DependencyProperty.Register(nameof(IsVisible), typeof(bool), typeof(HamburgerMenuItemBase), new PropertyMetadata(true)); + public static readonly DependencyProperty IsVisibleProperty = DependencyProperty.Register(nameof(IsVisible), typeof(bool), typeof(HamburgerMenuItemBase), new PropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets or sets a value that specifies an user specific value. @@ -45,7 +46,7 @@ public bool IsVisible set { - this.SetValue(IsVisibleProperty, value); + this.SetValue(IsVisibleProperty, BooleanBoxes.Box(value)); } } diff --git a/src/MahApps.Metro/Controls/Helper/ControlsHelper.cs b/src/MahApps.Metro/Controls/Helper/ControlsHelper.cs index ad64313e35..ebd2d9c5f0 100644 --- a/src/MahApps.Metro/Controls/Helper/ControlsHelper.cs +++ b/src/MahApps.Metro/Controls/Helper/ControlsHelper.cs @@ -3,6 +3,7 @@ using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Media; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -71,7 +72,7 @@ public static readonly DependencyProperty RecognizesAccessKeyProperty "RecognizesAccessKey", typeof(bool), typeof(ControlsHelper), - new FrameworkPropertyMetadata(true)); + new FrameworkPropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets the value if the inner ContentPresenter use AccessText in its style. @@ -94,7 +95,7 @@ public static bool GetRecognizesAccessKey(UIElement element) [AttachedPropertyBrowsableForType(typeof(SplitButton))] public static void SetRecognizesAccessKey(UIElement element, bool value) { - element.SetValue(RecognizesAccessKeyProperty, value); + element.SetValue(RecognizesAccessKeyProperty, BooleanBoxes.Box(value)); } public static readonly DependencyProperty FocusBorderBrushProperty @@ -230,7 +231,7 @@ public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.RegisterAttached("IsReadOnly", typeof(bool), typeof(ControlsHelper), - new FrameworkPropertyMetadata(false)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets a value indicating whether the child contents of the control are not editable. @@ -245,7 +246,7 @@ public static bool GetIsReadOnly(UIElement element) /// public static void SetIsReadOnly(UIElement element, bool value) { - element.SetValue(IsReadOnlyProperty, value); + element.SetValue(IsReadOnlyProperty, BooleanBoxes.Box(value)); } } } \ No newline at end of file diff --git a/src/MahApps.Metro/Controls/Helper/DataGridHelper.cs b/src/MahApps.Metro/Controls/Helper/DataGridHelper.cs index 4d38828f8b..1c741aa132 100644 --- a/src/MahApps.Metro/Controls/Helper/DataGridHelper.cs +++ b/src/MahApps.Metro/Controls/Helper/DataGridHelper.cs @@ -6,6 +6,7 @@ using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Media3D; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -461,7 +462,7 @@ public static readonly DependencyProperty EnableCellEditAssistProperty = DependencyProperty.RegisterAttached("EnableCellEditAssist", typeof(bool), typeof(DataGridHelper), - new PropertyMetadata(default(bool), EnableCellEditAssistPropertyChangedCallback)); + new PropertyMetadata(BooleanBoxes.FalseBox, EnableCellEditAssistPropertyChangedCallback)); /// /// Gets a value which indicates the preview cell editing is enabled or not. @@ -480,7 +481,7 @@ public static bool GetEnableCellEditAssist(DependencyObject element) [AttachedPropertyBrowsableForType(typeof(DataGrid))] public static void SetEnableCellEditAssist(DependencyObject element, bool value) { - element.SetValue(EnableCellEditAssistProperty, value); + element.SetValue(EnableCellEditAssistProperty, BooleanBoxes.Box(value)); } private static void EnableCellEditAssistPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -517,7 +518,7 @@ private static void DataGridOnPreviewMouseLeftButtonDown(object sender, MouseBut { dataGrid.CurrentCell = new DataGridCellInfo(dataGridCell); dataGrid.BeginEdit(); - toggleButton.SetCurrentValue(ToggleButton.IsCheckedProperty, !toggleButton.IsChecked); + toggleButton.SetCurrentValue(ToggleButton.IsCheckedProperty, BooleanBoxes.Box(!toggleButton.IsChecked.GetValueOrDefault())); dataGrid.CommitEdit(); e.Handled = true; } diff --git a/src/MahApps.Metro/Controls/Helper/ScrollViewerHelper.cs b/src/MahApps.Metro/Controls/Helper/ScrollViewerHelper.cs index ee514dda9d..f74149d0fa 100644 --- a/src/MahApps.Metro/Controls/Helper/ScrollViewerHelper.cs +++ b/src/MahApps.Metro/Controls/Helper/ScrollViewerHelper.cs @@ -2,6 +2,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -15,7 +16,7 @@ public static class ScrollViewerHelper DependencyProperty.RegisterAttached("VerticalScrollBarOnLeftSide", typeof(bool), typeof(ScrollViewerHelper), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.Inherits)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.Inherits)); /// Helper for getting from . /// to read from. @@ -34,7 +35,7 @@ public static bool GetVerticalScrollBarOnLeftSide(UIElement element) [AttachedPropertyBrowsableForType(typeof(ScrollViewer))] public static void SetVerticalScrollBarOnLeftSide(UIElement element, bool value) { - element.SetValue(VerticalScrollBarOnLeftSideProperty, value); + element.SetValue(VerticalScrollBarOnLeftSideProperty, BooleanBoxes.Box(value)); } /// @@ -44,7 +45,7 @@ public static void SetVerticalScrollBarOnLeftSide(UIElement element, bool value) DependencyProperty.RegisterAttached("IsHorizontalScrollWheelEnabled", typeof(bool), typeof(ScrollViewerHelper), - new PropertyMetadata(false, OnIsHorizontalScrollWheelEnabledPropertyChangedCallback)); + new PropertyMetadata(BooleanBoxes.FalseBox, OnIsHorizontalScrollWheelEnabledPropertyChangedCallback)); private static void OnIsHorizontalScrollWheelEnabledPropertyChangedCallback(DependencyObject o, DependencyPropertyChangedEventArgs e) { @@ -94,7 +95,7 @@ public static bool GetIsHorizontalScrollWheelEnabled(UIElement element) [AttachedPropertyBrowsableForType(typeof(UIElement))] public static void SetIsHorizontalScrollWheelEnabled(UIElement element, bool value) { - element.SetValue(IsHorizontalScrollWheelEnabledProperty, value); + element.SetValue(IsHorizontalScrollWheelEnabledProperty, BooleanBoxes.Box(value)); } /// diff --git a/src/MahApps.Metro/Controls/Helper/TabControlHelper.cs b/src/MahApps.Metro/Controls/Helper/TabControlHelper.cs index 43cf0ca64a..79281dc17d 100644 --- a/src/MahApps.Metro/Controls/Helper/TabControlHelper.cs +++ b/src/MahApps.Metro/Controls/Helper/TabControlHelper.cs @@ -4,6 +4,7 @@ using System.Windows.Controls.Primitives; using System.Windows.Input; using System.Windows.Media; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -48,7 +49,7 @@ public static void ClearStyle(this TabItem tabItem) DependencyProperty.RegisterAttached("CloseButtonEnabled", typeof(bool), typeof(TabControlHelper), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.Inherits)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.Inherits)); /// /// Gets whether a close button should be visible or not. @@ -67,7 +68,7 @@ public static bool GetCloseButtonEnabled(UIElement element) [AttachedPropertyBrowsableForType(typeof(TabItem))] public static void SetCloseButtonEnabled(UIElement element, bool value) { - element.SetValue(CloseButtonEnabledProperty, value); + element.SetValue(CloseButtonEnabledProperty, BooleanBoxes.Box(value)); } /// diff --git a/src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs b/src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs index 7ef682c67e..711e2584d4 100644 --- a/src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs +++ b/src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs @@ -13,6 +13,7 @@ using System.Windows.Data; using JetBrains.Annotations; using MahApps.Metro.Behaviors; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -43,20 +44,20 @@ public static class Spelling /// public class TextBoxHelper { - public static readonly DependencyProperty IsMonitoringProperty = DependencyProperty.RegisterAttached("IsMonitoring", typeof(bool), typeof(TextBoxHelper), new UIPropertyMetadata(false, OnIsMonitoringChanged)); + public static readonly DependencyProperty IsMonitoringProperty = DependencyProperty.RegisterAttached("IsMonitoring", typeof(bool), typeof(TextBoxHelper), new UIPropertyMetadata(BooleanBoxes.FalseBox, OnIsMonitoringChanged)); public static readonly DependencyProperty WatermarkProperty = DependencyProperty.RegisterAttached("Watermark", typeof(string), typeof(TextBoxHelper), new UIPropertyMetadata(string.Empty)); public static readonly DependencyProperty WatermarkAlignmentProperty = DependencyProperty.RegisterAttached("WatermarkAlignment", typeof(TextAlignment), typeof(TextBoxHelper), new FrameworkPropertyMetadata(TextAlignment.Left, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits)); public static readonly DependencyProperty WatermarkTrimmingProperty = DependencyProperty.RegisterAttached("WatermarkTrimming", typeof(TextTrimming), typeof(TextBoxHelper), new FrameworkPropertyMetadata(TextTrimming.None, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); public static readonly DependencyProperty WatermarkWrappingProperty = DependencyProperty.RegisterAttached("WatermarkWrapping", typeof(TextWrapping), typeof(TextBoxHelper), new FrameworkPropertyMetadata(TextWrapping.NoWrap, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); - public static readonly DependencyProperty UseFloatingWatermarkProperty = DependencyProperty.RegisterAttached("UseFloatingWatermark", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged)); + public static readonly DependencyProperty UseFloatingWatermarkProperty = DependencyProperty.RegisterAttached("UseFloatingWatermark", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, ButtonCommandOrClearTextChanged)); public static readonly DependencyProperty TextLengthProperty = DependencyProperty.RegisterAttached("TextLength", typeof(int), typeof(TextBoxHelper), new UIPropertyMetadata(0)); - public static readonly DependencyProperty ClearTextButtonProperty = DependencyProperty.RegisterAttached("ClearTextButton", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged)); - public static readonly DependencyProperty TextButtonProperty = DependencyProperty.RegisterAttached("TextButton", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged)); + public static readonly DependencyProperty ClearTextButtonProperty = DependencyProperty.RegisterAttached("ClearTextButton", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, ButtonCommandOrClearTextChanged)); + public static readonly DependencyProperty TextButtonProperty = DependencyProperty.RegisterAttached("TextButton", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, ButtonCommandOrClearTextChanged)); public static readonly DependencyProperty ButtonsAlignmentProperty = DependencyProperty.RegisterAttached("ButtonsAlignment", typeof(ButtonsAlignment), typeof(TextBoxHelper), new FrameworkPropertyMetadata(ButtonsAlignment.Right, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure)); /// /// The clear text button behavior property. It sets a click event to the button if the value is true. /// - public static readonly DependencyProperty IsClearTextButtonBehaviorEnabledProperty = DependencyProperty.RegisterAttached("IsClearTextButtonBehaviorEnabled", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, IsClearTextButtonBehaviorEnabledChanged)); + public static readonly DependencyProperty IsClearTextButtonBehaviorEnabledProperty = DependencyProperty.RegisterAttached("IsClearTextButtonBehaviorEnabled", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, IsClearTextButtonBehaviorEnabledChanged)); /// /// This property can be used to set the button width (PART_ClearText) of TextBox, PasswordBox, ComboBox, NumericUpDown @@ -70,12 +71,12 @@ public class TextBoxHelper public static readonly DependencyProperty ButtonFontFamilyProperty = DependencyProperty.RegisterAttached("ButtonFontFamily", typeof(FontFamily), typeof(TextBoxHelper), new FrameworkPropertyMetadata(new FontFamilyConverter().ConvertFromString("Marlett"))); public static readonly DependencyProperty ButtonFontSizeProperty = DependencyProperty.RegisterAttached("ButtonFontSize", typeof(double), typeof(TextBoxHelper), new FrameworkPropertyMetadata(SystemFonts.MessageFontSize)); - public static readonly DependencyProperty SelectAllOnFocusProperty = DependencyProperty.RegisterAttached("SelectAllOnFocus", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false)); - public static readonly DependencyProperty IsWaitingForDataProperty = DependencyProperty.RegisterAttached("IsWaitingForData", typeof(bool), typeof(TextBoxHelper), new UIPropertyMetadata(false)); + public static readonly DependencyProperty SelectAllOnFocusProperty = DependencyProperty.RegisterAttached("SelectAllOnFocus", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); + public static readonly DependencyProperty IsWaitingForDataProperty = DependencyProperty.RegisterAttached("IsWaitingForData", typeof(bool), typeof(TextBoxHelper), new UIPropertyMetadata(BooleanBoxes.FalseBox)); - public static readonly DependencyProperty HasTextProperty = DependencyProperty.RegisterAttached("HasText", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsRender)); + public static readonly DependencyProperty HasTextProperty = DependencyProperty.RegisterAttached("HasText", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsRender)); - public static readonly DependencyProperty IsSpellCheckContextMenuEnabledProperty = DependencyProperty.RegisterAttached("IsSpellCheckContextMenuEnabled", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(default(bool), IsSpellCheckContextMenuEnabledChanged)); + public static readonly DependencyProperty IsSpellCheckContextMenuEnabledProperty = DependencyProperty.RegisterAttached("IsSpellCheckContextMenuEnabled", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, IsSpellCheckContextMenuEnabledChanged)); /// /// This property can be used to retrieve the watermark using the of bound property. @@ -83,7 +84,7 @@ public class TextBoxHelper /// /// Setting this property to true will uses reflection. /// - public static readonly DependencyProperty AutoWatermarkProperty = DependencyProperty.RegisterAttached("AutoWatermark", typeof(bool), typeof(TextBoxHelper), new PropertyMetadata(default(bool), OnAutoWatermarkChanged)); + public static readonly DependencyProperty AutoWatermarkProperty = DependencyProperty.RegisterAttached("AutoWatermark", typeof(bool), typeof(TextBoxHelper), new PropertyMetadata(BooleanBoxes.FalseBox, OnAutoWatermarkChanged)); private static readonly Dictionary AutoWatermarkPropertyMapping = new Dictionary { @@ -109,7 +110,7 @@ public static bool GetIsSpellCheckContextMenuEnabled(UIElement element) [AttachedPropertyBrowsableForType(typeof(TextBoxBase))] public static void SetIsSpellCheckContextMenuEnabled(UIElement element, bool value) { - element.SetValue(IsSpellCheckContextMenuEnabledProperty, value); + element.SetValue(IsSpellCheckContextMenuEnabledProperty, BooleanBoxes.Box(value)); } [Category(AppName.MahApps)] @@ -138,7 +139,7 @@ public static bool GetAutoWatermark(DependencyObject element) /// public static void SetAutoWatermark(DependencyObject element, bool value) { - element.SetValue(AutoWatermarkProperty, value); + element.SetValue(AutoWatermarkProperty, BooleanBoxes.Box(value)); } private static void OnAutoWatermarkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -222,7 +223,7 @@ private static void IsSpellCheckContextMenuEnabledChanged(DependencyObject d, De if (e.OldValue != e.NewValue) { - tb.SetCurrentValue(SpellCheck.IsEnabledProperty, (bool)e.NewValue); + tb.SetCurrentValue(SpellCheck.IsEnabledProperty, BooleanBoxes.Box((bool)e.NewValue)); if ((bool)e.NewValue) { tb.ContextMenuOpening += TextBoxBaseContextMenuOpening; @@ -354,7 +355,7 @@ private static void RemoveSpellCheckMenuItems([CanBeNull] ContextMenu contextMen public static void SetIsWaitingForData(DependencyObject obj, bool value) { - obj.SetValue(IsWaitingForDataProperty, value); + obj.SetValue(IsWaitingForDataProperty, BooleanBoxes.Box(value)); } [Category(AppName.MahApps)] @@ -367,7 +368,7 @@ public static bool GetIsWaitingForData(DependencyObject obj) public static void SetSelectAllOnFocus(DependencyObject obj, bool value) { - obj.SetValue(SelectAllOnFocusProperty, value); + obj.SetValue(SelectAllOnFocusProperty, BooleanBoxes.Box(value)); } public static bool GetSelectAllOnFocus(DependencyObject obj) @@ -377,7 +378,7 @@ public static bool GetSelectAllOnFocus(DependencyObject obj) public static void SetIsMonitoring(DependencyObject obj, bool value) { - obj.SetValue(IsMonitoringProperty, value); + obj.SetValue(IsMonitoringProperty, BooleanBoxes.Box(value)); } [Category(AppName.MahApps)] @@ -511,7 +512,7 @@ public static bool GetUseFloatingWatermark(DependencyObject obj) public static void SetUseFloatingWatermark(DependencyObject obj, bool value) { - obj.SetValue(UseFloatingWatermarkProperty, value); + obj.SetValue(UseFloatingWatermarkProperty, BooleanBoxes.Box(value)); } /// @@ -530,7 +531,7 @@ public static bool GetHasText(DependencyObject obj) public static void SetHasText(DependencyObject obj, bool value) { - obj.SetValue(HasTextProperty, value); + obj.SetValue(HasTextProperty, BooleanBoxes.Box(value)); } private static void OnIsMonitoringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -717,7 +718,7 @@ public static bool GetClearTextButton(DependencyObject d) /// public static void SetClearTextButton(DependencyObject obj, bool value) { - obj.SetValue(ClearTextButtonProperty, value); + obj.SetValue(ClearTextButtonProperty, BooleanBoxes.Box(value)); } /// @@ -734,7 +735,7 @@ public static bool GetTextButton(DependencyObject d) /// public static void SetTextButton(DependencyObject obj, bool value) { - obj.SetValue(TextButtonProperty, value); + obj.SetValue(TextButtonProperty, BooleanBoxes.Box(value)); } /// @@ -770,7 +771,7 @@ public static bool GetIsClearTextButtonBehaviorEnabled(Button d) [AttachedPropertyBrowsableForType(typeof(ButtonBase))] public static void SetIsClearTextButtonBehaviorEnabled(Button obj, bool value) { - obj.SetValue(IsClearTextButtonBehaviorEnabledProperty, value); + obj.SetValue(IsClearTextButtonBehaviorEnabledProperty, BooleanBoxes.Box(value)); } [Category(AppName.MahApps)] diff --git a/src/MahApps.Metro/Controls/Helper/ValidationHelper.cs b/src/MahApps.Metro/Controls/Helper/ValidationHelper.cs index 15f2a9be2c..aad5eccc03 100644 --- a/src/MahApps.Metro/Controls/Helper/ValidationHelper.cs +++ b/src/MahApps.Metro/Controls/Helper/ValidationHelper.cs @@ -1,5 +1,6 @@ using System.ComponentModel; using System.Windows; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -12,7 +13,7 @@ public static readonly DependencyProperty CloseOnMouseLeftButtonDownProperty = DependencyProperty.RegisterAttached("CloseOnMouseLeftButtonDown", typeof(bool), typeof(ValidationHelper), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets whether if the popup can be closed by left mouse button down. @@ -31,7 +32,7 @@ public static bool GetCloseOnMouseLeftButtonDown(UIElement element) [AttachedPropertyBrowsableForType(typeof(UIElement))] public static void SetCloseOnMouseLeftButtonDown(UIElement element, bool value) { - element.SetValue(CloseOnMouseLeftButtonDownProperty, value); + element.SetValue(CloseOnMouseLeftButtonDownProperty, BooleanBoxes.Box(value)); } /// @@ -41,7 +42,7 @@ public static readonly DependencyProperty ShowValidationErrorOnMouseOverProperty = DependencyProperty.RegisterAttached("ShowValidationErrorOnMouseOver", typeof(bool), typeof(ValidationHelper), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets whether the validation error text will be shown when hovering the validation triangle. @@ -60,7 +61,7 @@ public static bool GetShowValidationErrorOnMouseOver(UIElement element) [AttachedPropertyBrowsableForType(typeof(UIElement))] public static void SetShowValidationErrorOnMouseOver(UIElement element, bool value) { - element.SetValue(ShowValidationErrorOnMouseOverProperty, value); + element.SetValue(ShowValidationErrorOnMouseOverProperty, BooleanBoxes.Box(value)); } } } \ No newline at end of file diff --git a/src/MahApps.Metro/Controls/HotKeyBox.cs b/src/MahApps.Metro/Controls/HotKeyBox.cs index 932d813097..cc37311868 100644 --- a/src/MahApps.Metro/Controls/HotKeyBox.cs +++ b/src/MahApps.Metro/Controls/HotKeyBox.cs @@ -6,6 +6,7 @@ using System.Windows.Controls; using ControlzEx.Native; using ControlzEx.Standard; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { [TemplatePart(Name = PART_TextBox, Type = typeof(TextBox))] @@ -30,12 +31,12 @@ private static void OnHotKeyChanged(DependencyObject d, DependencyPropertyChange } public static readonly DependencyProperty AreModifierKeysRequiredProperty = DependencyProperty.Register( - nameof(AreModifierKeysRequired), typeof(bool), typeof(HotKeyBox), new PropertyMetadata(default(bool))); + nameof(AreModifierKeysRequired), typeof(bool), typeof(HotKeyBox), new PropertyMetadata(BooleanBoxes.FalseBox)); public bool AreModifierKeysRequired { get { return (bool) GetValue(AreModifierKeysRequiredProperty); } - set { SetValue(AreModifierKeysRequiredProperty, value); } + set { SetValue(AreModifierKeysRequiredProperty, BooleanBoxes.Box(value)); } } private static readonly DependencyPropertyKey TextPropertyKey = DependencyProperty.RegisterReadOnly( diff --git a/src/MahApps.Metro/Controls/MetroContentControl.cs b/src/MahApps.Metro/Controls/MetroContentControl.cs index 0ae5138dfc..ea6d834add 100644 --- a/src/MahApps.Metro/Controls/MetroContentControl.cs +++ b/src/MahApps.Metro/Controls/MetroContentControl.cs @@ -1,6 +1,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media.Animation; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -18,7 +19,7 @@ public static readonly DependencyProperty ReverseTransitionProperty = DependencyProperty.Register(nameof(ReverseTransition), typeof(bool), typeof(MetroContentControl), - new FrameworkPropertyMetadata(false)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets whether the reverse version of the transition should be used. @@ -26,7 +27,7 @@ public static readonly DependencyProperty ReverseTransitionProperty public bool ReverseTransition { get => (bool)this.GetValue(ReverseTransitionProperty); - set => this.SetValue(ReverseTransitionProperty, value); + set => this.SetValue(ReverseTransitionProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -34,7 +35,7 @@ public static readonly DependencyProperty TransitionsEnabledProperty = DependencyProperty.Register(nameof(TransitionsEnabled), typeof(bool), typeof(MetroContentControl), - new FrameworkPropertyMetadata(true)); + new FrameworkPropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets or sets the value if a transition should be used or not. @@ -42,7 +43,7 @@ public static readonly DependencyProperty TransitionsEnabledProperty public bool TransitionsEnabled { get => (bool)this.GetValue(TransitionsEnabledProperty); - set => this.SetValue(TransitionsEnabledProperty, value); + set => this.SetValue(TransitionsEnabledProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -50,7 +51,7 @@ public static readonly DependencyProperty OnlyLoadTransitionProperty = DependencyProperty.Register(nameof(OnlyLoadTransition), typeof(bool), typeof(MetroContentControl), - new FrameworkPropertyMetadata(false)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets whether the transition should be used only at the loaded event of the control. @@ -58,7 +59,7 @@ public static readonly DependencyProperty OnlyLoadTransitionProperty public bool OnlyLoadTransition { get => (bool)this.GetValue(OnlyLoadTransitionProperty); - set => this.SetValue(OnlyLoadTransitionProperty, value); + set => this.SetValue(OnlyLoadTransitionProperty, BooleanBoxes.Box(value)); } /// Identifies the routed event. @@ -98,7 +99,7 @@ public static readonly DependencyPropertyKey IsTransitioningPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsTransitioning), typeof(bool), typeof(MetroContentControl), - new PropertyMetadata(default(bool))); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// Identifies the dependency property. public static readonly DependencyProperty IsTransitioningProperty = IsTransitioningPropertyKey.DependencyProperty; @@ -109,7 +110,7 @@ public static readonly DependencyPropertyKey IsTransitioningPropertyKey public bool IsTransitioning { get => (bool)this.GetValue(IsTransitioningProperty); - protected set => this.SetValue(IsTransitioningPropertyKey, value); + protected set => this.SetValue(IsTransitioningPropertyKey, BooleanBoxes.Box(value)); } public MetroContentControl() diff --git a/src/MahApps.Metro/Controls/MetroTabControl.cs b/src/MahApps.Metro/Controls/MetroTabControl.cs index ad56f4e6e1..cbe3b12c3c 100644 --- a/src/MahApps.Metro/Controls/MetroTabControl.cs +++ b/src/MahApps.Metro/Controls/MetroTabControl.cs @@ -7,6 +7,7 @@ using System.Windows.Input; using ControlzEx.Controls; using JetBrains.Annotations; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -24,12 +25,12 @@ static MetroTabControl() } /// Identifies the dependency property. - public static readonly DependencyProperty KeepVisualTreeInMemoryWhenChangingTabsProperty = DependencyProperty.Register(nameof(KeepVisualTreeInMemoryWhenChangingTabs), typeof(bool), typeof(MetroTabControl), new PropertyMetadata(false)); + public static readonly DependencyProperty KeepVisualTreeInMemoryWhenChangingTabsProperty = DependencyProperty.Register(nameof(KeepVisualTreeInMemoryWhenChangingTabs), typeof(bool), typeof(MetroTabControl), new PropertyMetadata(BooleanBoxes.FalseBox)); public bool KeepVisualTreeInMemoryWhenChangingTabs { get { return (bool)GetValue(KeepVisualTreeInMemoryWhenChangingTabsProperty); } - set { SetValue(KeepVisualTreeInMemoryWhenChangingTabsProperty, value); } + set { SetValue(KeepVisualTreeInMemoryWhenChangingTabsProperty, BooleanBoxes.Box(value)); } } } diff --git a/src/MahApps.Metro/Controls/MetroTabItem.cs b/src/MahApps.Metro/Controls/MetroTabItem.cs index cb6258cc94..50c8e35d6a 100644 --- a/src/MahApps.Metro/Controls/MetroTabItem.cs +++ b/src/MahApps.Metro/Controls/MetroTabItem.cs @@ -1,6 +1,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Input; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -18,7 +19,7 @@ public MetroTabItem() DependencyProperty.Register(nameof(CloseButtonEnabled), typeof(bool), typeof(MetroTabItem), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.Inherits)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.Inherits)); /// /// Gets/sets whether the Close Button is visible. @@ -26,7 +27,7 @@ public MetroTabItem() public bool CloseButtonEnabled { get { return (bool)GetValue(CloseButtonEnabledProperty); } - set { SetValue(CloseButtonEnabledProperty, value); } + set { SetValue(CloseButtonEnabledProperty, BooleanBoxes.Box(value)); } } public static readonly DependencyProperty CloseTabCommandProperty = diff --git a/src/MahApps.Metro/Controls/MetroThumbContentControl.cs b/src/MahApps.Metro/Controls/MetroThumbContentControl.cs index 7cc68835f6..9496610919 100644 --- a/src/MahApps.Metro/Controls/MetroThumbContentControl.cs +++ b/src/MahApps.Metro/Controls/MetroThumbContentControl.cs @@ -4,6 +4,7 @@ using System.Windows; using System.Windows.Automation.Peers; using System.Windows.Input; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -73,7 +74,7 @@ public static readonly DependencyPropertyKey IsDraggingPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsDragging), typeof(bool), typeof(MetroThumbContentControl), - new FrameworkPropertyMetadata(default(bool))); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); /// /// DependencyProperty for the IsDragging property. @@ -86,7 +87,7 @@ public static readonly DependencyPropertyKey IsDraggingPropertyKey public bool IsDragging { get { return (bool)this.GetValue(IsDraggingProperty); } - protected set { this.SetValue(IsDraggingPropertyKey, value); } + protected set { this.SetValue(IsDraggingPropertyKey, BooleanBoxes.Box(value)); } } public void CancelDragAction() diff --git a/src/MahApps.Metro/Controls/MetroWindow.cs b/src/MahApps.Metro/Controls/MetroWindow.cs index 113657e01b..e142bf5402 100644 --- a/src/MahApps.Metro/Controls/MetroWindow.cs +++ b/src/MahApps.Metro/Controls/MetroWindow.cs @@ -19,6 +19,7 @@ using JetBrains.Annotations; using MahApps.Metro.Behaviors; using MahApps.Metro.Controls.Dialogs; +using MahApps.Metro.ValueBoxes; using Microsoft.Xaml.Behaviors; namespace MahApps.Metro.Controls @@ -54,48 +55,48 @@ public class MetroWindow : Window private const string PART_FlyoutModal = "PART_FlyoutModal"; private const string PART_Content = "PART_Content"; - public static readonly DependencyProperty ShowIconOnTitleBarProperty = DependencyProperty.Register(nameof(ShowIconOnTitleBar), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true, OnShowIconOnTitleBarPropertyChangedCallback)); + public static readonly DependencyProperty ShowIconOnTitleBarProperty = DependencyProperty.Register(nameof(ShowIconOnTitleBar), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox, OnShowIconOnTitleBarPropertyChangedCallback)); public static readonly DependencyProperty IconEdgeModeProperty = DependencyProperty.Register(nameof(IconEdgeMode), typeof(EdgeMode), typeof(MetroWindow), new PropertyMetadata(EdgeMode.Aliased)); public static readonly DependencyProperty IconBitmapScalingModeProperty = DependencyProperty.Register(nameof(IconBitmapScalingMode), typeof(BitmapScalingMode), typeof(MetroWindow), new PropertyMetadata(BitmapScalingMode.HighQuality)); public static readonly DependencyProperty IconScalingModeProperty = DependencyProperty.Register(nameof(IconScalingMode), typeof(MultiFrameImageMode), typeof(MetroWindow), new FrameworkPropertyMetadata(MultiFrameImageMode.ScaleDownLargerFrame, FrameworkPropertyMetadataOptions.AffectsRender)); - public static readonly DependencyProperty ShowTitleBarProperty = DependencyProperty.Register(nameof(ShowTitleBar), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true, OnShowTitleBarPropertyChangedCallback, OnShowTitleBarCoerceValueCallback)); + public static readonly DependencyProperty ShowTitleBarProperty = DependencyProperty.Register(nameof(ShowTitleBar), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox, OnShowTitleBarPropertyChangedCallback, OnShowTitleBarCoerceValueCallback)); - public static readonly DependencyProperty ShowDialogsOverTitleBarProperty = DependencyProperty.Register(nameof(ShowDialogsOverTitleBar), typeof(bool), typeof(MetroWindow), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); + public static readonly DependencyProperty ShowDialogsOverTitleBarProperty = DependencyProperty.Register(nameof(ShowDialogsOverTitleBar), typeof(bool), typeof(MetroWindow), new FrameworkPropertyMetadata(BooleanBoxes.TrueBox, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); - public static readonly DependencyPropertyKey IsAnyDialogOpenPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsAnyDialogOpen), typeof(bool), typeof(MetroWindow), new PropertyMetadata(false)); + public static readonly DependencyPropertyKey IsAnyDialogOpenPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsAnyDialogOpen), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty IsAnyDialogOpenProperty = IsAnyDialogOpenPropertyKey.DependencyProperty; - public static readonly DependencyProperty ShowMinButtonProperty = DependencyProperty.Register(nameof(ShowMinButton), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty ShowMaxRestoreButtonProperty = DependencyProperty.Register(nameof(ShowMaxRestoreButton), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty ShowCloseButtonProperty = DependencyProperty.Register(nameof(ShowCloseButton), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly DependencyProperty ShowMinButtonProperty = DependencyProperty.Register(nameof(ShowMinButton), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); + public static readonly DependencyProperty ShowMaxRestoreButtonProperty = DependencyProperty.Register(nameof(ShowMaxRestoreButton), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); + public static readonly DependencyProperty ShowCloseButtonProperty = DependencyProperty.Register(nameof(ShowCloseButton), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); - public static readonly DependencyProperty IsMinButtonEnabledProperty = DependencyProperty.Register(nameof(IsMinButtonEnabled), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty IsMaxRestoreButtonEnabledProperty = DependencyProperty.Register(nameof(IsMaxRestoreButtonEnabled), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty IsCloseButtonEnabledProperty = DependencyProperty.Register(nameof(IsCloseButtonEnabled), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly DependencyProperty IsMinButtonEnabledProperty = DependencyProperty.Register(nameof(IsMinButtonEnabled), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); + public static readonly DependencyProperty IsMaxRestoreButtonEnabledProperty = DependencyProperty.Register(nameof(IsMaxRestoreButtonEnabled), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); + public static readonly DependencyProperty IsCloseButtonEnabledProperty = DependencyProperty.Register(nameof(IsCloseButtonEnabled), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); - public static readonly DependencyPropertyKey IsCloseButtonEnabledWithDialogPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsCloseButtonEnabledWithDialog), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly DependencyPropertyKey IsCloseButtonEnabledWithDialogPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsCloseButtonEnabledWithDialog), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); /// /// Identifies the dependency property. /// public static readonly DependencyProperty IsCloseButtonEnabledWithDialogProperty = IsCloseButtonEnabledWithDialogPropertyKey.DependencyProperty; - public static readonly DependencyProperty ShowSystemMenuProperty = DependencyProperty.Register(nameof(ShowSystemMenu), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty ShowSystemMenuOnRightClickProperty = DependencyProperty.Register(nameof(ShowSystemMenuOnRightClick), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly DependencyProperty ShowSystemMenuProperty = DependencyProperty.Register(nameof(ShowSystemMenu), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); + public static readonly DependencyProperty ShowSystemMenuOnRightClickProperty = DependencyProperty.Register(nameof(ShowSystemMenuOnRightClick), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); public static readonly DependencyProperty TitleBarHeightProperty = DependencyProperty.Register(nameof(TitleBarHeight), typeof(int), typeof(MetroWindow), new PropertyMetadata(30, TitleBarHeightPropertyChangedCallback)); public static readonly DependencyProperty TitleCharacterCasingProperty = DependencyProperty.Register(nameof(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(nameof(TitleAlignment), typeof(HorizontalAlignment), typeof(MetroWindow), new PropertyMetadata(HorizontalAlignment.Stretch, OnTitleAlignmentChanged)); - public static readonly DependencyProperty SaveWindowPositionProperty = DependencyProperty.Register(nameof(SaveWindowPosition), typeof(bool), typeof(MetroWindow), new PropertyMetadata(false)); + public static readonly DependencyProperty SaveWindowPositionProperty = DependencyProperty.Register(nameof(SaveWindowPosition), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.FalseBox)); public static readonly DependencyProperty WindowPlacementSettingsProperty = DependencyProperty.Register(nameof(WindowPlacementSettings), typeof(IWindowPlacementSettings), typeof(MetroWindow), new PropertyMetadata(null)); public static readonly DependencyProperty TitleForegroundProperty = DependencyProperty.Register(nameof(TitleForeground), typeof(Brush), typeof(MetroWindow)); public static readonly DependencyProperty FlyoutsProperty = DependencyProperty.Register(nameof(Flyouts), typeof(FlyoutsControl), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds)); - public static readonly DependencyProperty WindowTransitionsEnabledProperty = DependencyProperty.Register(nameof(WindowTransitionsEnabled), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly DependencyProperty WindowTransitionsEnabledProperty = DependencyProperty.Register(nameof(WindowTransitionsEnabled), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); public static readonly DependencyProperty MetroDialogOptionsProperty = DependencyProperty.Register(nameof(MetroDialogOptions), typeof(MetroDialogSettings), typeof(MetroWindow), new PropertyMetadata(default(MetroDialogSettings))); public static readonly DependencyProperty WindowTitleBrushProperty = DependencyProperty.Register(nameof(WindowTitleBrush), typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Transparent)); @@ -131,10 +132,10 @@ public class MetroWindow : Window public static readonly DependencyProperty WindowButtonCommandsOverlayBehaviorProperty = DependencyProperty.Register(nameof(WindowButtonCommandsOverlayBehavior), typeof(OverlayBehavior), typeof(MetroWindow), new PropertyMetadata(OverlayBehavior.Always, OnShowTitleBarPropertyChangedCallback)); public static readonly DependencyProperty IconOverlayBehaviorProperty = DependencyProperty.Register(nameof(IconOverlayBehavior), typeof(OverlayBehavior), typeof(MetroWindow), new PropertyMetadata(OverlayBehavior.Never, OnShowTitleBarPropertyChangedCallback)); - public static readonly DependencyProperty UseNoneWindowStyleProperty = DependencyProperty.Register(nameof(UseNoneWindowStyle), typeof(bool), typeof(MetroWindow), new PropertyMetadata(false, OnUseNoneWindowStylePropertyChangedCallback)); + public static readonly DependencyProperty UseNoneWindowStyleProperty = DependencyProperty.Register(nameof(UseNoneWindowStyle), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.FalseBox, OnUseNoneWindowStylePropertyChangedCallback)); public static readonly DependencyProperty OverrideDefaultWindowCommandsBrushProperty = DependencyProperty.Register(nameof(OverrideDefaultWindowCommandsBrush), typeof(Brush), typeof(MetroWindow)); - public static readonly DependencyProperty IsWindowDraggableProperty = DependencyProperty.Register(nameof(IsWindowDraggable), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly DependencyProperty IsWindowDraggableProperty = DependencyProperty.Register(nameof(IsWindowDraggable), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); FrameworkElement icon; UIElement titleBar; @@ -188,7 +189,7 @@ public MetroDialogSettings MetroDialogOptions public bool IsWindowDraggable { get { return (bool)GetValue(IsWindowDraggableProperty); } - set { SetValue(IsWindowDraggableProperty, value); } + set { SetValue(IsWindowDraggableProperty, BooleanBoxes.Box(value)); } } public WindowCommandsOverlayBehavior LeftWindowCommandsOverlayBehavior @@ -221,7 +222,7 @@ public OverlayBehavior IconOverlayBehavior public bool WindowTransitionsEnabled { get { return (bool)this.GetValue(WindowTransitionsEnabledProperty); } - set { SetValue(WindowTransitionsEnabledProperty, value); } + set { SetValue(WindowTransitionsEnabledProperty, BooleanBoxes.Box(value)); } } /// @@ -285,13 +286,13 @@ public WindowButtonCommands WindowButtonCommands public bool IgnoreTaskbarOnMaximize { get { return (bool)this.GetValue(IgnoreTaskbarOnMaximizeProperty); } - set { SetValue(IgnoreTaskbarOnMaximizeProperty, value); } + set { SetValue(IgnoreTaskbarOnMaximizeProperty, BooleanBoxes.Box(value)); } } /// /// Identifies the dependency property. /// - public static readonly DependencyProperty IgnoreTaskbarOnMaximizeProperty = DependencyProperty.Register(nameof(IgnoreTaskbarOnMaximize), typeof(bool), typeof(MetroWindow), new PropertyMetadata(false)); + public static readonly DependencyProperty IgnoreTaskbarOnMaximizeProperty = DependencyProperty.Register(nameof(IgnoreTaskbarOnMaximize), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets resize border thickness. This enables animation, styling, binding, etc... @@ -314,13 +315,13 @@ public Thickness ResizeBorderThickness public bool KeepBorderOnMaximize { get { return (bool)this.GetValue(KeepBorderOnMaximizeProperty); } - set { this.SetValue(KeepBorderOnMaximizeProperty, value); } + set { this.SetValue(KeepBorderOnMaximizeProperty, BooleanBoxes.Box(value)); } } /// /// for . /// - public static readonly DependencyProperty KeepBorderOnMaximizeProperty = DependencyProperty.Register(nameof(KeepBorderOnMaximize), typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly DependencyProperty KeepBorderOnMaximizeProperty = DependencyProperty.Register(nameof(KeepBorderOnMaximize), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.TrueBox)); /// /// 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. @@ -331,13 +332,13 @@ public bool KeepBorderOnMaximize public bool TryToBeFlickerFree { get { return (bool)this.GetValue(TryToBeFlickerFreeProperty); } - set { this.SetValue(TryToBeFlickerFreeProperty, value); } + set { this.SetValue(TryToBeFlickerFreeProperty, BooleanBoxes.Box(value)); } } /// /// for . /// - public static readonly DependencyProperty TryToBeFlickerFreeProperty = DependencyProperty.Register(nameof(TryToBeFlickerFree), typeof(bool), typeof(MetroWindow), new PropertyMetadata(false)); + public static readonly DependencyProperty TryToBeFlickerFreeProperty = DependencyProperty.Register(nameof(TryToBeFlickerFree), typeof(bool), typeof(MetroWindow), new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets/sets the brush used for the titlebar's foreground. @@ -354,7 +355,7 @@ public Brush TitleForeground public bool SaveWindowPosition { get { return (bool)GetValue(SaveWindowPositionProperty); } - set { SetValue(SaveWindowPositionProperty, value); } + set { SetValue(SaveWindowPositionProperty, BooleanBoxes.Box(value)); } } public IWindowPlacementSettings WindowPlacementSettings @@ -377,7 +378,7 @@ public virtual IWindowPlacementSettings GetWindowPlacementSettings() public bool ShowIconOnTitleBar { get { return (bool)GetValue(ShowIconOnTitleBarProperty); } - set { SetValue(ShowIconOnTitleBarProperty, value); } + set { SetValue(ShowIconOnTitleBarProperty, BooleanBoxes.Box(value)); } } private static void OnShowIconOnTitleBarPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -395,7 +396,7 @@ private static void OnShowIconOnTitleBarPropertyChangedCallback(DependencyObject public bool ShowDialogsOverTitleBar { get { return (bool)GetValue(ShowDialogsOverTitleBarProperty); } - set { SetValue(ShowDialogsOverTitleBarProperty, value); } + set { SetValue(ShowDialogsOverTitleBarProperty, BooleanBoxes.Box(value)); } } /// @@ -404,7 +405,7 @@ public bool ShowDialogsOverTitleBar public bool IsAnyDialogOpen { get { return (bool)GetValue(IsAnyDialogOpenProperty); } - private set { SetValue(IsAnyDialogOpenPropertyKey, value); } + private set { SetValue(IsAnyDialogOpenPropertyKey, BooleanBoxes.Box(value)); } } /// @@ -440,7 +441,7 @@ public MultiFrameImageMode IconScalingMode public bool ShowTitleBar { get { return (bool)GetValue(ShowTitleBarProperty); } - set { SetValue(ShowTitleBarProperty, value); } + set { SetValue(ShowTitleBarProperty, BooleanBoxes.Box(value)); } } private static void OnShowTitleBarPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -468,7 +469,7 @@ private static object OnShowTitleBarCoerceValueCallback(DependencyObject d, obje public bool UseNoneWindowStyle { get { return (bool)GetValue(UseNoneWindowStyleProperty); } - set { SetValue(UseNoneWindowStyleProperty, value); } + set { SetValue(UseNoneWindowStyleProperty, BooleanBoxes.Box(value)); } } private static void OnUseNoneWindowStylePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) @@ -481,7 +482,7 @@ private static void OnUseNoneWindowStylePropertyChangedCallback(DependencyObject // UseNoneWindowStyle means no title bar, window commands or min, max, close buttons if (useNoneWindowStyle) { - ((MetroWindow)d).SetCurrentValue(ShowTitleBarProperty, false); + ((MetroWindow)d).SetCurrentValue(ShowTitleBarProperty, BooleanBoxes.FalseBox); } } } @@ -492,7 +493,7 @@ private static void OnUseNoneWindowStylePropertyChangedCallback(DependencyObject public bool ShowMinButton { get { return (bool)GetValue(ShowMinButtonProperty); } - set { SetValue(ShowMinButtonProperty, value); } + set { SetValue(ShowMinButtonProperty, BooleanBoxes.Box(value)); } } /// @@ -501,7 +502,7 @@ public bool ShowMinButton public bool ShowMaxRestoreButton { get { return (bool)GetValue(ShowMaxRestoreButtonProperty); } - set { SetValue(ShowMaxRestoreButtonProperty, value); } + set { SetValue(ShowMaxRestoreButtonProperty, BooleanBoxes.Box(value)); } } /// @@ -510,7 +511,7 @@ public bool ShowMaxRestoreButton public bool ShowCloseButton { get { return (bool)GetValue(ShowCloseButtonProperty); } - set { SetValue(ShowCloseButtonProperty, value); } + set { SetValue(ShowCloseButtonProperty, BooleanBoxes.Box(value)); } } /// @@ -519,7 +520,7 @@ public bool ShowCloseButton public bool IsMinButtonEnabled { get { return (bool)GetValue(IsMinButtonEnabledProperty); } - set { SetValue(IsMinButtonEnabledProperty, value); } + set { SetValue(IsMinButtonEnabledProperty, BooleanBoxes.Box(value)); } } /// @@ -528,7 +529,7 @@ public bool IsMinButtonEnabled public bool IsMaxRestoreButtonEnabled { get { return (bool)GetValue(IsMaxRestoreButtonEnabledProperty); } - set { SetValue(IsMaxRestoreButtonEnabledProperty, value); } + set { SetValue(IsMaxRestoreButtonEnabledProperty, BooleanBoxes.Box(value)); } } /// @@ -537,7 +538,7 @@ public bool IsMaxRestoreButtonEnabled public bool IsCloseButtonEnabled { get { return (bool)GetValue(IsCloseButtonEnabledProperty); } - set { SetValue(IsCloseButtonEnabledProperty, value); } + set { SetValue(IsCloseButtonEnabledProperty, BooleanBoxes.Box(value)); } } /// @@ -546,7 +547,7 @@ public bool IsCloseButtonEnabled public bool IsCloseButtonEnabledWithDialog { get { return (bool)GetValue(IsCloseButtonEnabledWithDialogProperty); } - private set { SetValue(IsCloseButtonEnabledWithDialogPropertyKey, value); } + private set { SetValue(IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.Box(value)); } } /// @@ -555,7 +556,7 @@ public bool IsCloseButtonEnabledWithDialog public bool ShowSystemMenu { get { return (bool)GetValue(ShowSystemMenuProperty); } - set { SetValue(ShowSystemMenuProperty, value); } + set { SetValue(ShowSystemMenuProperty, BooleanBoxes.Box(value)); } } /// @@ -564,7 +565,7 @@ public bool ShowSystemMenu public bool ShowSystemMenuOnRightClick { get { return (bool)GetValue(ShowSystemMenuOnRightClickProperty); } - set { SetValue(ShowSystemMenuOnRightClickProperty, value); } + set { SetValue(ShowSystemMenuOnRightClickProperty, BooleanBoxes.Box(value)); } } /// diff --git a/src/MahApps.Metro/Controls/NumericUpDown.cs b/src/MahApps.Metro/Controls/NumericUpDown.cs index fc96982cab..6914689578 100644 --- a/src/MahApps.Metro/Controls/NumericUpDown.cs +++ b/src/MahApps.Metro/Controls/NumericUpDown.cs @@ -9,6 +9,7 @@ using System.Windows.Controls; using System.Windows.Controls.Primitives; using System.Windows.Input; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -196,7 +197,7 @@ public static readonly DependencyProperty SpeedupProperty = DependencyProperty.Register(nameof(Speedup), typeof(bool), typeof(NumericUpDown), - new FrameworkPropertyMetadata(true, OnSpeedupPropertyChanged)); + new FrameworkPropertyMetadata(BooleanBoxes.TrueBox, OnSpeedupPropertyChanged)); private static void OnSpeedupPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { @@ -215,7 +216,7 @@ private static void OnSpeedupPropertyChanged(DependencyObject d, DependencyPrope public bool Speedup { get => (bool)this.GetValue(SpeedupProperty); - set => this.SetValue(SpeedupProperty, value); + set => this.SetValue(SpeedupProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -293,7 +294,7 @@ public static readonly DependencyProperty InterceptArrowKeysProperty = DependencyProperty.Register(nameof(InterceptArrowKeys), typeof(bool), typeof(NumericUpDown), - new FrameworkPropertyMetadata(true)); + new FrameworkPropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets or sets a value indicating whether the user can use the arrow keys and to change the value. @@ -304,7 +305,7 @@ public static readonly DependencyProperty InterceptArrowKeysProperty public bool InterceptArrowKeys { get => (bool)this.GetValue(InterceptArrowKeysProperty); - set => this.SetValue(InterceptArrowKeysProperty, value); + set => this.SetValue(InterceptArrowKeysProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -312,7 +313,7 @@ public static readonly DependencyProperty InterceptMouseWheelProperty = DependencyProperty.Register(nameof(InterceptMouseWheel), typeof(bool), typeof(NumericUpDown), - new FrameworkPropertyMetadata(true)); + new FrameworkPropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets or sets a value indicating whether the user can use the mouse wheel to change the value. @@ -322,7 +323,7 @@ public static readonly DependencyProperty InterceptMouseWheelProperty public bool InterceptMouseWheel { get => (bool)this.GetValue(InterceptMouseWheelProperty); - set => this.SetValue(InterceptMouseWheelProperty, value); + set => this.SetValue(InterceptMouseWheelProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -330,7 +331,7 @@ public static readonly DependencyProperty InterceptManualEnterProperty = DependencyProperty.Register(nameof(InterceptManualEnter), typeof(bool), typeof(NumericUpDown), - new PropertyMetadata(true, OnInterceptManualEnterPropertyChanged)); + new PropertyMetadata(BooleanBoxes.TrueBox, OnInterceptManualEnterPropertyChanged)); private static void OnInterceptManualEnterPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { @@ -351,7 +352,7 @@ private static void OnInterceptManualEnterPropertyChanged(DependencyObject depen public bool InterceptManualEnter { get => (bool)this.GetValue(InterceptManualEnterProperty); - set => this.SetValue(InterceptManualEnterProperty, value); + set => this.SetValue(InterceptManualEnterProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -502,7 +503,7 @@ public static readonly DependencyProperty TrackMouseWheelWhenMouseOverProperty = DependencyProperty.Register(nameof(TrackMouseWheelWhenMouseOver), typeof(bool), typeof(NumericUpDown), - new FrameworkPropertyMetadata(default(bool))); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets a value indicating whether the control must have the focus in order to change values using the mouse wheel. @@ -517,7 +518,7 @@ public static readonly DependencyProperty TrackMouseWheelWhenMouseOverProperty public bool TrackMouseWheelWhenMouseOver { get => (bool)this.GetValue(TrackMouseWheelWhenMouseOverProperty); - set => this.SetValue(TrackMouseWheelWhenMouseOverProperty, value); + set => this.SetValue(TrackMouseWheelWhenMouseOverProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -544,7 +545,7 @@ public static readonly DependencyProperty HideUpDownButtonsProperty = DependencyProperty.Register(nameof(HideUpDownButtons), typeof(bool), typeof(NumericUpDown), - new PropertyMetadata(default(bool))); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets a value indicating whether the up/down button of the control are visible. @@ -569,7 +570,7 @@ public static readonly DependencyProperty HideUpDownButtonsProperty public bool HideUpDownButtons { get => (bool)this.GetValue(HideUpDownButtonsProperty); - set => this.SetValue(HideUpDownButtonsProperty, value); + set => this.SetValue(HideUpDownButtonsProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -596,7 +597,7 @@ public static readonly DependencyProperty UpDownButtonsFocusableProperty = DependencyProperty.Register(nameof(UpDownButtonsFocusable), typeof(bool), typeof(NumericUpDown), - new PropertyMetadata(true)); + new PropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets or sets whether the up and down buttons will got the focus when using them. @@ -607,7 +608,7 @@ public static readonly DependencyProperty UpDownButtonsFocusableProperty public bool UpDownButtonsFocusable { get => (bool)this.GetValue(UpDownButtonsFocusableProperty); - set => this.SetValue(UpDownButtonsFocusableProperty, value); + set => this.SetValue(UpDownButtonsFocusableProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -615,7 +616,7 @@ public static readonly DependencyProperty SwitchUpDownButtonsProperty = DependencyProperty.Register(nameof(SwitchUpDownButtons), typeof(bool), typeof(NumericUpDown), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets a value indicating whether the up/down buttons will be switched. @@ -625,7 +626,7 @@ public static readonly DependencyProperty SwitchUpDownButtonsProperty public bool SwitchUpDownButtons { get => (bool)this.GetValue(SwitchUpDownButtonsProperty); - set => this.SetValue(SwitchUpDownButtonsProperty, value); + set => this.SetValue(SwitchUpDownButtonsProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -633,7 +634,7 @@ public static readonly DependencyProperty ChangeValueOnTextChangedProperty = DependencyProperty.Register(nameof(ChangeValueOnTextChanged), typeof(bool), typeof(NumericUpDown), - new PropertyMetadata(true)); + new PropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets or sets a value indicating whether the value will be changed directly on every TextBox text changed input event or when using the Enter key. @@ -642,7 +643,7 @@ public static readonly DependencyProperty ChangeValueOnTextChangedProperty public bool ChangeValueOnTextChanged { get => (bool)this.GetValue(ChangeValueOnTextChangedProperty); - set => this.SetValue(ChangeValueOnTextChangedProperty, value); + set => this.SetValue(ChangeValueOnTextChangedProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -722,7 +723,7 @@ public static readonly DependencyProperty SnapToMultipleOfIntervalProperty = DependencyProperty.Register(nameof(SnapToMultipleOfInterval), typeof(bool), typeof(NumericUpDown), - new PropertyMetadata(default(bool), OnSnapToMultipleOfIntervalPropertyChanged)); + new PropertyMetadata(BooleanBoxes.FalseBox, OnSnapToMultipleOfIntervalPropertyChanged)); private static void OnSnapToMultipleOfIntervalPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { @@ -750,7 +751,7 @@ private static void OnSnapToMultipleOfIntervalPropertyChanged(DependencyObject d public bool SnapToMultipleOfInterval { get => (bool)this.GetValue(SnapToMultipleOfIntervalProperty); - set => this.SetValue(SnapToMultipleOfIntervalProperty, value); + set => this.SetValue(SnapToMultipleOfIntervalProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. diff --git a/src/MahApps.Metro/Controls/ProgressRing.cs b/src/MahApps.Metro/Controls/ProgressRing.cs index 46e2dfc9e0..7e6e6a2a59 100644 --- a/src/MahApps.Metro/Controls/ProgressRing.cs +++ b/src/MahApps.Metro/Controls/ProgressRing.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Windows; using System.Windows.Controls; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -32,12 +33,12 @@ public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register(nameof(IsActive), typeof(bool), typeof(ProgressRing), - new PropertyMetadata(true, OnIsActivePropertyChanged)); + new PropertyMetadata(BooleanBoxes.TrueBox, OnIsActivePropertyChanged)); public bool IsActive { get => (bool)this.GetValue(IsActiveProperty); - set => this.SetValue(IsActiveProperty, value); + set => this.SetValue(IsActiveProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -45,12 +46,12 @@ public static readonly DependencyProperty IsLargeProperty = DependencyProperty.Register(nameof(IsLarge), typeof(bool), typeof(ProgressRing), - new PropertyMetadata(true, OnIsLargePropertyChanged)); + new PropertyMetadata(BooleanBoxes.TrueBox, OnIsLargePropertyChanged)); public bool IsLarge { get => (bool)this.GetValue(IsLargeProperty); - set => this.SetValue(IsLargeProperty, value); + set => this.SetValue(IsLargeProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -128,7 +129,7 @@ static ProgressRing() { var ring = ringObject as ProgressRing; - ring?.SetCurrentValue(IsActiveProperty, (Visibility)e.NewValue == Visibility.Visible); + ring?.SetCurrentValue(IsActiveProperty, BooleanBoxes.Box((Visibility)e.NewValue == Visibility.Visible)); } })); } diff --git a/src/MahApps.Metro/Controls/RangeSlider.cs b/src/MahApps.Metro/Controls/RangeSlider.cs index 7e82fa4713..9165e9dd1d 100644 --- a/src/MahApps.Metro/Controls/RangeSlider.cs +++ b/src/MahApps.Metro/Controls/RangeSlider.cs @@ -10,6 +10,7 @@ using System.Windows.Threading; using ControlzEx; using JetBrains.Annotations; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -423,7 +424,7 @@ public static readonly DependencyProperty MoveWholeRangeProperty = DependencyProperty.Register(nameof(MoveWholeRange), typeof(bool), typeof(RangeSlider), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Get/sets whether whole range will be moved when press on right/left/central part of control @@ -433,7 +434,7 @@ public static readonly DependencyProperty MoveWholeRangeProperty public bool MoveWholeRange { get => (bool)this.GetValue(MoveWholeRangeProperty); - set => this.SetValue(MoveWholeRangeProperty, value); + set => this.SetValue(MoveWholeRangeProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -441,7 +442,7 @@ public static readonly DependencyProperty ExtendedModeProperty = DependencyProperty.Register(nameof(ExtendedMode), typeof(bool), typeof(RangeSlider), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Get/sets whether possibility to make manipulations inside range with left/right mouse buttons + cotrol button @@ -451,7 +452,7 @@ public static readonly DependencyProperty ExtendedModeProperty public bool ExtendedMode { get => (bool)this.GetValue(ExtendedModeProperty); - set => this.SetValue(ExtendedModeProperty, value); + set => this.SetValue(ExtendedModeProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -459,7 +460,7 @@ public static readonly DependencyProperty IsSnapToTickEnabledProperty = DependencyProperty.Register(nameof(IsSnapToTickEnabled), typeof(bool), typeof(RangeSlider), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Get/sets whether possibility to make manipulations inside range with left/right mouse buttons + cotrol button @@ -469,7 +470,7 @@ public static readonly DependencyProperty IsSnapToTickEnabledProperty public bool IsSnapToTickEnabled { get => (bool)this.GetValue(IsSnapToTickEnabledProperty); - set => this.SetValue(IsSnapToTickEnabledProperty, value); + set => this.SetValue(IsSnapToTickEnabledProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -557,7 +558,7 @@ public static readonly DependencyProperty IsMoveToPointEnabledProperty = DependencyProperty.Register(nameof(IsMoveToPointEnabled), typeof(bool), typeof(RangeSlider), - new PropertyMetadata(false)); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Get or sets IsMoveToPoint feature which will enable/disable moving to exact point inside control when user clicked on it @@ -568,7 +569,7 @@ public static readonly DependencyProperty IsMoveToPointEnabledProperty public bool IsMoveToPointEnabled { get => (bool)this.GetValue(IsMoveToPointEnabledProperty); - set => this.SetValue(IsMoveToPointEnabledProperty, value); + set => this.SetValue(IsMoveToPointEnabledProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -690,7 +691,7 @@ public static readonly DependencyProperty IsSelectionRangeEnabledProperty = DependencyProperty.Register(nameof(IsSelectionRangeEnabled), typeof(bool), typeof(RangeSlider), - new FrameworkPropertyMetadata(false)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets a value that indicates whether the displays a selection range along the . @@ -703,7 +704,7 @@ public static readonly DependencyProperty IsSelectionRangeEnabledProperty public bool IsSelectionRangeEnabled { get => (bool)this.GetValue(IsSelectionRangeEnabledProperty); - set => this.SetValue(IsSelectionRangeEnabledProperty, value); + set => this.SetValue(IsSelectionRangeEnabledProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. diff --git a/src/MahApps.Metro/Controls/SplitButton.cs b/src/MahApps.Metro/Controls/SplitButton.cs index 0990e555f7..04e98c2615 100644 --- a/src/MahApps.Metro/Controls/SplitButton.cs +++ b/src/MahApps.Metro/Controls/SplitButton.cs @@ -6,6 +6,7 @@ using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -303,12 +304,12 @@ private void ButtonClick(object sender, RoutedEventArgs e) e.RoutedEvent = ClickEvent; this.RaiseEvent(e); - this.SetCurrentValue(IsDropDownOpenProperty, false); + this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.FalseBox); } private void ExpanderMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { - this.SetCurrentValue(IsDropDownOpenProperty, !this.IsDropDownOpen); + this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.Box(!this.IsDropDownOpen)); e.Handled = true; } diff --git a/src/MahApps.Metro/Controls/SplitView/SplitView.cs b/src/MahApps.Metro/Controls/SplitView/SplitView.cs index d4d9fb016d..ef641e156e 100644 --- a/src/MahApps.Metro/Controls/SplitView/SplitView.cs +++ b/src/MahApps.Metro/Controls/SplitView/SplitView.cs @@ -1,4 +1,6 @@ -namespace MahApps.Metro.Controls +using MahApps.Metro.ValueBoxes; + +namespace MahApps.Metro.Controls { using System; using System.Collections; @@ -114,7 +116,7 @@ public static readonly DependencyProperty IsPaneOpenProperty = DependencyProperty.Register(nameof(IsPaneOpen), typeof(bool), typeof(SplitView), - new PropertyMetadata(false, OnIsPaneOpenChanged)); + new PropertyMetadata(BooleanBoxes.FalseBox, OnIsPaneOpenChanged)); private static void OnIsPaneOpenChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { @@ -145,7 +147,7 @@ private static void OnIsPaneOpenChanged(DependencyObject d, DependencyPropertyCh public bool IsPaneOpen { get => (bool)this.GetValue(IsPaneOpenProperty); - set => this.SetValue(IsPaneOpenProperty, value); + set => this.SetValue(IsPaneOpenProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -289,7 +291,7 @@ public double MaximumOpenPaneLength } /// Identifies the dependency property. - public static readonly DependencyProperty CanResizeOpenPaneProperty = DependencyProperty.Register(nameof(CanResizeOpenPane), typeof(bool), typeof(SplitView), new PropertyMetadata(false, OnCanResizeOpenPanePropertyChangedCallback)); + public static readonly DependencyProperty CanResizeOpenPaneProperty = DependencyProperty.Register(nameof(CanResizeOpenPane), typeof(bool), typeof(SplitView), new PropertyMetadata(BooleanBoxes.FalseBox, OnCanResizeOpenPanePropertyChangedCallback)); private static void OnCanResizeOpenPanePropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) { @@ -305,7 +307,7 @@ private static void OnCanResizeOpenPanePropertyChangedCallback(DependencyObject public bool CanResizeOpenPane { get => (bool)this.GetValue(CanResizeOpenPaneProperty); - set => this.SetValue(CanResizeOpenPaneProperty, value); + set => this.SetValue(CanResizeOpenPaneProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -618,13 +620,13 @@ protected void OnIsPaneOpenChanged() } else { - this.SetCurrentValue(IsPaneOpenProperty, false); + this.SetCurrentValue(IsPaneOpenProperty, BooleanBoxes.FalseBox); } } private void OnLightDismiss(object sender, MouseButtonEventArgs e) { - this.SetCurrentValue(IsPaneOpenProperty, false); + this.SetCurrentValue(IsPaneOpenProperty, BooleanBoxes.FalseBox); } } } \ No newline at end of file diff --git a/src/MahApps.Metro/Controls/Tile.cs b/src/MahApps.Metro/Controls/Tile.cs index b818cc63ee..de91c116a4 100644 --- a/src/MahApps.Metro/Controls/Tile.cs +++ b/src/MahApps.Metro/Controls/Tile.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Windows; using System.Windows.Controls; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -70,12 +71,12 @@ public string Count set { SetValue(CountProperty, value); } } - public static readonly DependencyProperty KeepDraggingProperty = DependencyProperty.Register(nameof(KeepDragging), typeof(bool), typeof(Tile), new PropertyMetadata(true)); + public static readonly DependencyProperty KeepDraggingProperty = DependencyProperty.Register(nameof(KeepDragging), typeof(bool), typeof(Tile), new PropertyMetadata(BooleanBoxes.TrueBox)); public bool KeepDragging { get { return (bool)GetValue(KeepDraggingProperty); } - set { SetValue(KeepDraggingProperty, value); } + set { SetValue(KeepDraggingProperty, BooleanBoxes.Box(value)); } } public static readonly DependencyProperty TiltFactorProperty = DependencyProperty.Register(nameof(TiltFactor), typeof(int), typeof(Tile), new PropertyMetadata(5)); diff --git a/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs b/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs index a777316914..dee6e00bbb 100644 --- a/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs +++ b/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs @@ -7,6 +7,7 @@ using System.Windows.Data; using System.Windows.Input; using System.Windows.Threading; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -206,7 +207,7 @@ private void CalendarPreviewKeyDown(object sender, RoutedEventArgs e) if (keyEventArgs.Key == Key.Escape || ((keyEventArgs.Key == Key.Enter || keyEventArgs.Key == Key.Space) && this.calendar.DisplayMode == CalendarMode.Month)) { - this.SetCurrentValue(IsDropDownOpenProperty, false); + this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.FalseBox); if (keyEventArgs.Key == Key.Escape) { this.SetCurrentValue(SelectedDateTimeProperty, this.originalSelectedDateTime); diff --git a/src/MahApps.Metro/Controls/TimePicker/TimePickerBase.cs b/src/MahApps.Metro/Controls/TimePicker/TimePickerBase.cs index eb12d27cab..ff2a03134b 100644 --- a/src/MahApps.Metro/Controls/TimePicker/TimePickerBase.cs +++ b/src/MahApps.Metro/Controls/TimePicker/TimePickerBase.cs @@ -11,6 +11,7 @@ using System.Windows.Data; using System.Windows.Input; using System.Windows.Markup; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -221,7 +222,7 @@ public static readonly DependencyProperty IsClockVisibleProperty = DependencyProperty.Register(nameof(IsClockVisible), typeof(bool), typeof(TimePickerBase), - new PropertyMetadata(true)); + new PropertyMetadata(BooleanBoxes.TrueBox)); /// /// Gets or sets a value indicating whether the clock of this control is visible in the user interface (UI). This is a @@ -238,7 +239,7 @@ public static readonly DependencyProperty IsClockVisibleProperty public bool IsClockVisible { get => (bool)this.GetValue(IsClockVisibleProperty); - set => this.SetValue(IsClockVisibleProperty, value); + set => this.SetValue(IsClockVisibleProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -246,7 +247,7 @@ public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register(nameof(IsReadOnly), typeof(bool), typeof(TimePickerBase), - new PropertyMetadata(default(bool))); + new PropertyMetadata(BooleanBoxes.FalseBox)); /// /// Gets or sets a value indicating whether the contents of the are not editable. @@ -257,7 +258,7 @@ public static readonly DependencyProperty IsReadOnlyProperty public bool IsReadOnly { get => (bool)this.GetValue(IsReadOnlyProperty); - set => this.SetValue(IsReadOnlyProperty, value); + set => this.SetValue(IsReadOnlyProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -429,7 +430,7 @@ private static readonly DependencyPropertyKey IsDatePickerVisiblePropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsDatePickerVisible), typeof(bool), typeof(TimePickerBase), - new PropertyMetadata(true)); + new PropertyMetadata(BooleanBoxes.TrueBox)); /// Identifies the dependency property. [SuppressMessage("StyleCop.CSharp.OrderingRules", "SA1202:ElementsMustBeOrderedByAccess", Justification = "Otherwise we have \"Static member initializer refers to static member below or in other type part\" and thus resulting in having \"null\" as value")] @@ -441,7 +442,7 @@ private static readonly DependencyPropertyKey IsDatePickerVisiblePropertyKey public bool IsDatePickerVisible { get => (bool)this.GetValue(IsDatePickerVisibleProperty); - protected set => this.SetValue(IsDatePickerVisiblePropertyKey, value); + protected set => this.SetValue(IsDatePickerVisiblePropertyKey, BooleanBoxes.Box(value)); } #endregion @@ -657,7 +658,7 @@ private void OutsideCapturedElementHandler(object sender, MouseButtonEventArgs e return; } - this.SetCurrentValue(IsDropDownOpenProperty, false); + this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.FalseBox); } } @@ -679,7 +680,7 @@ private void PopUp_Opened(object sender, EventArgs e) { if (!this.IsDropDownOpen) { - this.SetCurrentValue(IsDropDownOpenProperty, true); + this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.TrueBox); } this.OnPopUpOpened(); @@ -694,7 +695,7 @@ private void PopUp_Closed(object sender, EventArgs e) { if (this.IsDropDownOpen) { - this.SetCurrentValue(IsDropDownOpenProperty, false); + this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.FalseBox); } this.OnPopUpClosed(); @@ -765,7 +766,7 @@ private void TimePickerPreviewKeyDown(object sender, RoutedEventArgs e) if (keyEventArgs.Key == Key.Escape || keyEventArgs.Key == Key.Enter || keyEventArgs.Key == Key.Space) { - this.SetCurrentValue(IsDropDownOpenProperty, false); + this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.FalseBox); if (keyEventArgs.Key == Key.Escape) { this.SetCurrentValue(SelectedDateTimeProperty, this.originalSelectedDateTime); @@ -978,7 +979,7 @@ private void TogglePopUp() { if (this.IsDropDownOpen) { - this.SetCurrentValue(IsDropDownOpenProperty, false); + this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.FalseBox); } else { @@ -989,7 +990,7 @@ private void TogglePopUp() else { this.SetSelectedDateTime(); - this.SetCurrentValue(IsDropDownOpenProperty, true); + this.SetCurrentValue(IsDropDownOpenProperty, BooleanBoxes.TrueBox); } } } diff --git a/src/MahApps.Metro/Controls/ToggleSwitch.cs b/src/MahApps.Metro/Controls/ToggleSwitch.cs index 786591b434..fe30462e0d 100644 --- a/src/MahApps.Metro/Controls/ToggleSwitch.cs +++ b/src/MahApps.Metro/Controls/ToggleSwitch.cs @@ -7,6 +7,7 @@ using System.Windows.Input; using System.Windows.Markup; using System.Windows.Media; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -107,7 +108,7 @@ public static readonly DependencyProperty IsOnProperty typeof(bool), typeof(ToggleSwitch), new FrameworkPropertyMetadata( - false, + BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault | FrameworkPropertyMetadataOptions.Journal, OnIsOnChanged)); @@ -134,7 +135,7 @@ private static void OnIsOnChanged(DependencyObject d, DependencyPropertyChangedE public bool IsOn { get => (bool)this.GetValue(IsOnProperty); - set => this.SetValue(IsOnProperty, value); + set => this.SetValue(IsOnProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -308,7 +309,7 @@ private static readonly DependencyPropertyKey IsPressedPropertyKey = DependencyProperty.RegisterReadOnly(nameof(IsPressed), typeof(bool), typeof(ToggleSwitch), - null); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox)); /// Identifies the dependency property. public static readonly DependencyProperty IsPressedProperty = IsPressedPropertyKey.DependencyProperty; @@ -319,7 +320,7 @@ private static readonly DependencyPropertyKey IsPressedPropertyKey public bool IsPressed { get => (bool)this.GetValue(IsPressedProperty); - protected set => this.SetValue(IsPressedPropertyKey, value); + protected set => this.SetValue(IsPressedPropertyKey, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -633,7 +634,7 @@ private void UpdateVisualStates(bool useTransitions) private void Toggle() { var newValue = !this.IsOn; - this.SetCurrentValue(IsOnProperty, newValue); + this.SetCurrentValue(IsOnProperty, BooleanBoxes.Box(newValue)); CommandHelpers.ExecuteCommandSource(this); CommandHelpers.ExecuteCommandSource(this, newValue ? this.OnCommand : this.OffCommand); diff --git a/src/MahApps.Metro/Controls/TransitioningContentControl.cs b/src/MahApps.Metro/Controls/TransitioningContentControl.cs index db383aa0c1..9f5969864f 100644 --- a/src/MahApps.Metro/Controls/TransitioningContentControl.cs +++ b/src/MahApps.Metro/Controls/TransitioningContentControl.cs @@ -11,6 +11,7 @@ using System.Windows; using System.Windows.Controls; using System.Windows.Media.Animation; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -76,9 +77,9 @@ public class TransitioningContentControl : ContentControl public const TransitionType DefaultTransitionState = TransitionType.Default; - public static readonly DependencyProperty IsTransitioningProperty = DependencyProperty.Register(nameof(IsTransitioning), typeof(bool), typeof(TransitioningContentControl), new PropertyMetadata(OnIsTransitioningPropertyChanged)); + public static readonly DependencyProperty IsTransitioningProperty = DependencyProperty.Register(nameof(IsTransitioning), typeof(bool), typeof(TransitioningContentControl), new PropertyMetadata(BooleanBoxes.FalseBox, OnIsTransitioningPropertyChanged)); public static readonly DependencyProperty TransitionProperty = DependencyProperty.Register(nameof(Transition), typeof(TransitionType), typeof(TransitioningContentControl), new FrameworkPropertyMetadata(TransitionType.Default, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.Inherits, OnTransitionPropertyChanged)); - public static readonly DependencyProperty RestartTransitionOnContentChangeProperty = DependencyProperty.Register(nameof(RestartTransitionOnContentChange), typeof(bool), typeof(TransitioningContentControl), new PropertyMetadata(false, OnRestartTransitionOnContentChangePropertyChanged)); + public static readonly DependencyProperty RestartTransitionOnContentChangeProperty = DependencyProperty.Register(nameof(RestartTransitionOnContentChange), typeof(bool), typeof(TransitioningContentControl), new PropertyMetadata(BooleanBoxes.FalseBox, OnRestartTransitionOnContentChangePropertyChanged)); public static readonly DependencyProperty CustomVisualStatesProperty = DependencyProperty.Register(nameof(CustomVisualStates), typeof(ObservableCollection), typeof(TransitioningContentControl), new PropertyMetadata(null)); public static readonly DependencyProperty CustomVisualStatesNameProperty = DependencyProperty.Register(nameof(CustomVisualStatesName), typeof(string), typeof(TransitioningContentControl), new PropertyMetadata("CustomTransition")); @@ -106,7 +107,7 @@ public bool IsTransitioning private set { this.allowIsTransitioningPropertyWrite = true; - this.SetValue(IsTransitioningProperty, value); + this.SetValue(IsTransitioningProperty, BooleanBoxes.Box(value)); this.allowIsTransitioningPropertyWrite = false; } } @@ -120,7 +121,7 @@ public TransitionType Transition public bool RestartTransitionOnContentChange { get { return (bool)this.GetValue(RestartTransitionOnContentChangeProperty); } - set { this.SetValue(RestartTransitionOnContentChangeProperty, value); } + set { this.SetValue(RestartTransitionOnContentChangeProperty, BooleanBoxes.Box(value)); } } private static void OnIsTransitioningPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) diff --git a/src/MahApps.Metro/Controls/WindowCommands.cs b/src/MahApps.Metro/Controls/WindowCommands.cs index 3623b73b0f..2b129ec4fb 100644 --- a/src/MahApps.Metro/Controls/WindowCommands.cs +++ b/src/MahApps.Metro/Controls/WindowCommands.cs @@ -8,6 +8,7 @@ using System.Windows.Data; using ControlzEx; using ControlzEx.Theming; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -97,7 +98,7 @@ public static readonly DependencyProperty ShowSeparatorsProperty = DependencyProperty.Register(nameof(ShowSeparators), typeof(bool), typeof(WindowCommands), - new FrameworkPropertyMetadata(true, + new FrameworkPropertyMetadata(BooleanBoxes.TrueBox, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnShowSeparatorsPropertyChanged)); @@ -115,7 +116,7 @@ private static void OnShowSeparatorsPropertyChanged(DependencyObject d, Dependen public bool ShowSeparators { get => (bool)this.GetValue(ShowSeparatorsProperty); - set => this.SetValue(ShowSeparatorsProperty, value); + set => this.SetValue(ShowSeparatorsProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -123,7 +124,7 @@ public static readonly DependencyProperty ShowLastSeparatorProperty = DependencyProperty.Register(nameof(ShowLastSeparator), typeof(bool), typeof(WindowCommands), - new FrameworkPropertyMetadata(true, + new FrameworkPropertyMetadata(BooleanBoxes.TrueBox, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender, OnShowLastSeparatorPropertyChanged)); @@ -141,7 +142,7 @@ private static void OnShowLastSeparatorPropertyChanged(DependencyObject d, Depen public bool ShowLastSeparator { get => (bool)this.GetValue(ShowLastSeparatorProperty); - set => this.SetValue(ShowLastSeparatorProperty, value); + set => this.SetValue(ShowLastSeparatorProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. diff --git a/src/MahApps.Metro/Controls/WindowCommandsItem.cs b/src/MahApps.Metro/Controls/WindowCommandsItem.cs index 464129994f..c66f69b787 100644 --- a/src/MahApps.Metro/Controls/WindowCommandsItem.cs +++ b/src/MahApps.Metro/Controls/WindowCommandsItem.cs @@ -1,6 +1,7 @@ using System.Windows; using System.Windows.Controls; using ControlzEx; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { @@ -18,7 +19,7 @@ public class WindowCommandsItem : ContentControl DependencyProperty.Register(nameof(IsSeparatorVisible), typeof(bool), typeof(WindowCommandsItem), - new FrameworkPropertyMetadata(true, + new FrameworkPropertyMetadata(BooleanBoxes.TrueBox, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); /// @@ -27,7 +28,7 @@ public class WindowCommandsItem : ContentControl public bool IsSeparatorVisible { get => (bool)this.GetValue(IsSeparatorVisibleProperty); - set => this.SetValue(IsSeparatorVisibleProperty, value); + set => this.SetValue(IsSeparatorVisibleProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property.