diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuDefault.xaml.cs b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuDefault.xaml.cs index 82ff623d3d..553e840de8 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuDefault.xaml.cs +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/HamburgerMenuDefault.xaml.cs @@ -55,7 +55,7 @@ private void HamburgerMenuControl_OnItemInvoked(object sender, HamburgerMenuItem public class BindingProxy : Freezable { // Using a DependencyProperty as the backing store for Data. This enables animation, styling, binding, etc... - public static readonly DependencyProperty DataProperty = DependencyProperty.Register("Data", typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null)); + public static readonly DependencyProperty DataProperty = DependencyProperty.Register(nameof(Data), typeof(object), typeof(BindingProxy), new UIPropertyMetadata(null)); public object Data { @@ -71,7 +71,7 @@ protected override Freezable CreateInstanceCore() public static class ShowAboutCommand { - public static readonly RoutedCommand Command = new RoutedCommand("Command", typeof(ShowAboutCommand)); + public static readonly RoutedCommand Command = new RoutedCommand(nameof(Command), typeof(ShowAboutCommand)); static ShowAboutCommand() { diff --git a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml.cs b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml.cs index 848e786d7a..7203ae2be0 100644 --- a/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml.cs +++ b/src/MahApps.Metro.Samples/MahApps.Metro.Demo/MainWindow.xaml.cs @@ -29,7 +29,7 @@ public MainWindow() } public static readonly DependencyProperty ToggleFullScreenProperty = - DependencyProperty.Register("ToggleFullScreen", + DependencyProperty.Register(nameof(ToggleFullScreen), typeof(bool), typeof(MainWindow), new PropertyMetadata(default(bool), OnToggleFullScreenChanged)); @@ -63,7 +63,7 @@ public bool ToggleFullScreen } public static readonly DependencyProperty UseAccentForDialogsProperty = - DependencyProperty.Register("UseAccentForDialogs", + DependencyProperty.Register(nameof(UseAccentForDialogs), typeof(bool), typeof(MainWindow), new PropertyMetadata(default(bool), OnUseAccentForDialogsChanged)); 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/BindableResourceBehavior.cs b/src/MahApps.Metro/Behaviors/BindableResourceBehavior.cs index f56fc1e2fb..e9838cdd5a 100644 --- a/src/MahApps.Metro/Behaviors/BindableResourceBehavior.cs +++ b/src/MahApps.Metro/Behaviors/BindableResourceBehavior.cs @@ -6,8 +6,8 @@ namespace MahApps.Metro.Behaviors { public class BindableResourceBehavior : Behavior { - public static readonly DependencyProperty ResourceNameProperty = DependencyProperty.Register("ResourceName", typeof (string), typeof (BindableResourceBehavior), new PropertyMetadata(default(string))); - public static readonly DependencyProperty PropertyProperty = DependencyProperty.Register("Property", typeof (DependencyProperty), typeof (BindableResourceBehavior), new PropertyMetadata(default(DependencyProperty))); + public static readonly DependencyProperty ResourceNameProperty = DependencyProperty.Register(nameof(ResourceName), typeof (string), typeof (BindableResourceBehavior), new PropertyMetadata(default(string))); + public static readonly DependencyProperty PropertyProperty = DependencyProperty.Register(nameof(Property), typeof (DependencyProperty), typeof (BindableResourceBehavior), new PropertyMetadata(default(DependencyProperty))); protected override void OnAttached() { diff --git a/src/MahApps.Metro/Behaviors/DatePickerTextBoxBehavior.cs b/src/MahApps.Metro/Behaviors/DatePickerTextBoxBehavior.cs index 50293bd882..82d4b5d055 100644 --- a/src/MahApps.Metro/Behaviors/DatePickerTextBoxBehavior.cs +++ b/src/MahApps.Metro/Behaviors/DatePickerTextBoxBehavior.cs @@ -2,6 +2,7 @@ using System.Windows.Controls.Primitives; using System.Windows.Threading; using MahApps.Metro.Controls; +using MahApps.Metro.ValueBoxes; using Microsoft.Xaml.Behaviors; namespace MahApps.Metro.Behaviors @@ -29,7 +30,7 @@ private void OnTextChanged(object sender, TextChangedEventArgs e) private void SetHasTextProperty() { - this.AssociatedObject.TemplatedParent?.SetValue(TextBoxHelper.HasTextProperty, this.AssociatedObject.Text.Length > 0); + this.AssociatedObject.TemplatedParent?.SetCurrentValue(TextBoxHelper.HasTextProperty, BooleanBoxes.Box(this.AssociatedObject.Text.Length > 0)); } } } \ No newline at end of file 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 9b568a338e..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 { @@ -54,7 +55,7 @@ public sealed class ClipBorder : Decorator /// BorderThickness Dependency Property /// public static readonly DependencyProperty BorderThicknessProperty = - DependencyProperty.Register("BorderThickness", typeof(Thickness), typeof(ClipBorder), + DependencyProperty.Register(nameof(BorderThickness), typeof(Thickness), typeof(ClipBorder), new FrameworkPropertyMetadata(new Thickness(), FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender), OnValidateThickness); @@ -98,7 +99,7 @@ private static bool OnValidateThickness(object value) /// Padding Dependency Property /// public static readonly DependencyProperty PaddingProperty = - DependencyProperty.Register("Padding", typeof(Thickness), typeof(ClipBorder), + DependencyProperty.Register(nameof(Padding), typeof(Thickness), typeof(ClipBorder), new FrameworkPropertyMetadata(new Thickness(), FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender), OnValidateThickness); @@ -131,7 +132,7 @@ public Thickness Padding /// CornerRadius Dependency Property /// public static readonly DependencyProperty CornerRadiusProperty = - DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(ClipBorder), + DependencyProperty.Register(nameof(CornerRadius), typeof(CornerRadius), typeof(ClipBorder), new FrameworkPropertyMetadata(new CornerRadius(), FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender), OnValidateCornerRadius); @@ -175,7 +176,7 @@ private static bool OnValidateCornerRadius(object value) /// BorderBrush Dependency Property /// public static readonly DependencyProperty BorderBrushProperty = - DependencyProperty.Register("BorderBrush", typeof(Brush), typeof(ClipBorder), + DependencyProperty.Register(nameof(BorderBrush), typeof(Brush), typeof(ClipBorder), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender)); @@ -197,7 +198,7 @@ public Brush BorderBrush /// Background Dependency Property /// public static readonly DependencyProperty BackgroundProperty = - DependencyProperty.Register("Background", typeof(Brush), typeof(ClipBorder), + DependencyProperty.Register(nameof(Background), typeof(Brush), typeof(ClipBorder), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.SubPropertiesDoNotAffectRender)); @@ -219,8 +220,8 @@ public Brush Background /// OptimizeClipRendering Dependency Property /// public static readonly DependencyProperty OptimizeClipRenderingProperty = - DependencyProperty.Register("OptimizeClipRendering", typeof(bool), typeof(ClipBorder), - new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender)); + DependencyProperty.Register(nameof(OptimizeClipRendering), typeof(bool), typeof(ClipBorder), + 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..4aedfec52d 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 { @@ -131,7 +132,7 @@ private void CustomValidationPopup_Loaded(object sender, RoutedEventArgs e) return; } - this.SetValue(CanShowPropertyKey, false); + this.SetValue(CanShowPropertyKey, BooleanBoxes.FalseBox); var canShow = true; if (this.scrollViewer != null) @@ -205,7 +206,7 @@ private void CustomValidationPopup_Loaded(object sender, RoutedEventArgs e) } this.RefreshPosition(); - this.SetValue(CanShowPropertyKey, canShow); + this.SetValue(CanShowPropertyKey, BooleanBoxes.Box(canShow)); this.OnLoaded(); @@ -219,27 +220,27 @@ 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); + this.SetValue(CanShowPropertyKey, BooleanBoxes.TrueBox); } private void Flyout_IsOpenChanged(object sender, RoutedEventArgs e) { this.RefreshPosition(); - this.SetValue(CanShowPropertyKey, false); + this.SetValue(CanShowPropertyKey, BooleanBoxes.FalseBox); } private void Flyout_ClosingFinished(object sender, RoutedEventArgs e) { this.RefreshPosition(); - this.SetValue(CanShowPropertyKey, false); + this.SetValue(CanShowPropertyKey, BooleanBoxes.FalseBox); } private void OnTransitionStarted(object sender, RoutedEventArgs e) { this.RefreshPosition(); - this.SetValue(CanShowPropertyKey, false); + this.SetValue(CanShowPropertyKey, BooleanBoxes.FalseBox); } private void OnTransitionCompleted(object sender, RoutedEventArgs e) @@ -248,9 +249,9 @@ 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); + this.SetValue(CanShowPropertyKey, BooleanBoxes.TrueBox); } private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e) @@ -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/DialogManager.cs b/src/MahApps.Metro/Controls/Dialogs/DialogManager.cs index 22294be286..baaaf6d87c 100644 --- a/src/MahApps.Metro/Controls/Dialogs/DialogManager.cs +++ b/src/MahApps.Metro/Controls/Dialogs/DialogManager.cs @@ -5,6 +5,7 @@ using System.Windows.Controls; using System.Windows.Threading; using ControlzEx.Theming; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls.Dialogs { @@ -292,13 +293,14 @@ private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindo { if (window.metroActiveDialogContainer.Children.Count == 0) { - window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, true); + window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.TrueBox); window.RestoreFocus(); } else { var onTopShownDialogSettings = window.metroActiveDialogContainer.Children.OfType().LastOrDefault()?.DialogSettings; - window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, window.ShowDialogsOverTitleBar || onTopShownDialogSettings == null || onTopShownDialogSettings.OwnerCanCloseWithDialog); + var isCloseButtonEnabled = window.ShowDialogsOverTitleBar || onTopShownDialogSettings == null || onTopShownDialogSettings.OwnerCanCloseWithDialog; + window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.Box(isCloseButtonEnabled)); } }); }); @@ -308,7 +310,14 @@ private static Task HandleOverlayOnHide(MetroDialogSettings settings, MetroWindo private static Task HandleOverlayOnShow(MetroDialogSettings settings, MetroWindow window) { - return Task.Factory.StartNew(() => { window.Invoke(() => window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, window.ShowDialogsOverTitleBar || settings == null || settings.OwnerCanCloseWithDialog)); }) + return Task.Factory.StartNew(() => + { + window.Invoke(() => + { + var isCloseButtonEnabled = window.ShowDialogsOverTitleBar || settings == null || settings.OwnerCanCloseWithDialog; + window.SetValue(MetroWindow.IsCloseButtonEnabledWithDialogPropertyKey, BooleanBoxes.Box(isCloseButtonEnabled)); + }); + }) .ContinueWith(task => { return window.Invoke(() => @@ -510,7 +519,7 @@ private static void AddDialog(this MetroWindow window, BaseMetroDialog dialog) window.metroActiveDialogContainer.Children.Add(dialog); //add the dialog to the container} - window.SetValue(MetroWindow.IsAnyDialogOpenPropertyKey, true); + window.SetValue(MetroWindow.IsAnyDialogOpenPropertyKey, BooleanBoxes.TrueBox); } private static void RemoveDialog(this MetroWindow window, BaseMetroDialog dialog) @@ -532,7 +541,7 @@ private static void RemoveDialog(this MetroWindow window, BaseMetroDialog dialog window.metroInactiveDialogContainer.Children.Remove(dialog); } - window.SetValue(MetroWindow.IsAnyDialogOpenPropertyKey, window.metroActiveDialogContainer.Children.Count > 0); + window.SetValue(MetroWindow.IsAnyDialogOpenPropertyKey, BooleanBoxes.Box(window.metroActiveDialogContainer.Children.Count > 0)); } /// 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 2d4a49023d..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 { @@ -26,7 +27,7 @@ public class Flyout : HeaderedContentControl /// An event that is raised when IsOpen changes. /// public static readonly RoutedEvent IsOpenChangedEvent = - EventManager.RegisterRoutedEvent("IsOpenChanged", RoutingStrategy.Bubble, + EventManager.RegisterRoutedEvent(nameof(IsOpenChanged), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Flyout)); public event RoutedEventHandler IsOpenChanged @@ -39,7 +40,7 @@ public event RoutedEventHandler IsOpenChanged /// An event that is raised when the opening animation has finished. /// public static readonly RoutedEvent OpeningFinishedEvent = - EventManager.RegisterRoutedEvent("OpeningFinished", RoutingStrategy.Bubble, + EventManager.RegisterRoutedEvent(nameof(OpeningFinished), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Flyout)); public event RoutedEventHandler OpeningFinished @@ -52,7 +53,7 @@ public event RoutedEventHandler OpeningFinished /// An event that is raised when the closing animation has finished. /// public static readonly RoutedEvent ClosingFinishedEvent = - EventManager.RegisterRoutedEvent("ClosingFinished", RoutingStrategy.Bubble, + EventManager.RegisterRoutedEvent(nameof(ClosingFinished), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Flyout)); public event RoutedEventHandler ClosingFinished @@ -61,26 +62,26 @@ public event RoutedEventHandler ClosingFinished remove { this.RemoveHandler(ClosingFinishedEvent, value); } } - public static readonly DependencyProperty PositionProperty = DependencyProperty.Register("Position", typeof(Position), typeof(Flyout), new PropertyMetadata(Position.Left, PositionChanged)); - public static readonly DependencyProperty IsPinnedProperty = DependencyProperty.Register("IsPinned", typeof(bool), typeof(Flyout), new PropertyMetadata(true)); - public static readonly DependencyProperty IsOpenProperty = DependencyProperty.Register("IsOpen", typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, IsOpenedChanged)); - public static readonly DependencyProperty AnimateOnPositionChangeProperty = DependencyProperty.Register("AnimateOnPositionChange", typeof(bool), typeof(Flyout), new PropertyMetadata(true)); - public static readonly DependencyProperty AnimateOpacityProperty = DependencyProperty.Register("AnimateOpacity", typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(false, AnimateOpacityChanged)); - public static readonly DependencyProperty IsModalProperty = DependencyProperty.Register("IsModal", typeof(bool), typeof(Flyout)); + 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(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("CloseCommand", typeof(ICommand), typeof(Flyout), new UIPropertyMetadata(null)); - public static readonly DependencyProperty CloseCommandParameterProperty = DependencyProperty.Register("CloseCommandParameter", typeof(object), typeof(Flyout), new PropertyMetadata(null)); + 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)); - public static readonly DependencyProperty ThemeProperty = DependencyProperty.Register("Theme", typeof(FlyoutTheme), typeof(Flyout), new FrameworkPropertyMetadata(FlyoutTheme.Dark, ThemeChanged)); - public static readonly DependencyProperty ExternalCloseButtonProperty = DependencyProperty.Register("ExternalCloseButton", typeof(MouseButton), typeof(Flyout), new PropertyMetadata(MouseButton.Left)); - public static readonly DependencyProperty CloseButtonVisibilityProperty = DependencyProperty.Register("CloseButtonVisibility", typeof(Visibility), typeof(Flyout), new FrameworkPropertyMetadata(Visibility.Visible)); - public static readonly DependencyProperty CloseButtonIsCancelProperty = DependencyProperty.Register("CloseButtonIsCancel", typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(false)); - public static readonly DependencyProperty TitleVisibilityProperty = DependencyProperty.Register("TitleVisibility", typeof(Visibility), typeof(Flyout), new FrameworkPropertyMetadata(Visibility.Visible)); - public static readonly DependencyProperty AreAnimationsEnabledProperty = DependencyProperty.Register("AreAnimationsEnabled", typeof(bool), typeof(Flyout), new PropertyMetadata(true)); - public static readonly DependencyProperty FocusedElementProperty = DependencyProperty.Register("FocusedElement", typeof(FrameworkElement), typeof(Flyout), new UIPropertyMetadata(null)); - public static readonly DependencyProperty AllowFocusElementProperty = DependencyProperty.Register("AllowFocusElement", typeof(bool), typeof(Flyout), new PropertyMetadata(true)); - public static readonly DependencyProperty IsAutoCloseEnabledProperty = DependencyProperty.Register("IsAutoCloseEnabled", typeof(bool), typeof(Flyout), new FrameworkPropertyMetadata(false, IsAutoCloseEnabledChanged)); - public static readonly DependencyProperty AutoCloseIntervalProperty = DependencyProperty.Register("AutoCloseInterval", typeof(long), typeof(Flyout), new FrameworkPropertyMetadata(5000L, AutoCloseIntervalChanged)); + 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 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(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(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; } internal PropertyChangeNotifier ThemePropertyChangeNotifier { 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 5d255bc286..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 { @@ -13,11 +14,11 @@ namespace MahApps.Metro.Controls /// A FlyoutsControl is for displaying flyouts in a MetroWindow. /// /// - [StyleTypedProperty(Property = "ItemContainerStyle", StyleTargetType = typeof(Flyout))] + [StyleTypedProperty(Property = nameof(ItemContainerStyle), StyleTargetType = typeof(Flyout))] public class FlyoutsControl : ItemsControl { - public static readonly DependencyProperty OverrideExternalCloseButtonProperty = DependencyProperty.Register("OverrideExternalCloseButton", typeof(MouseButton?), typeof(FlyoutsControl), new PropertyMetadata(null)); - public static readonly DependencyProperty OverrideIsPinnedProperty = DependencyProperty.Register("OverrideIsPinned", typeof(bool), typeof(FlyoutsControl), new PropertyMetadata(false)); + 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(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/MahAppsCommands.cs b/src/MahApps.Metro/Controls/Helper/MahAppsCommands.cs index 945210bb17..bf5c50b46f 100644 --- a/src/MahApps.Metro/Controls/Helper/MahAppsCommands.cs +++ b/src/MahApps.Metro/Controls/Helper/MahAppsCommands.cs @@ -8,7 +8,7 @@ namespace MahApps.Metro.Controls { public static class MahAppsCommands { - public static ICommand ClearControlCommand { get; } = new RoutedUICommand("Clear", "ClearControlCommand", typeof(MahAppsCommands)); + public static ICommand ClearControlCommand { get; } = new RoutedUICommand("Clear", nameof(ClearControlCommand), typeof(MahAppsCommands)); static MahAppsCommands() { 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..48693d509a 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) @@ -642,7 +643,7 @@ private static void SetTextLength(TDependencyObject sender, F { var value = funcTextLength(sender); sender.SetValue(TextLengthProperty, value); - sender.SetValue(HasTextProperty, value >= 1); + sender.SetValue(HasTextProperty, BooleanBoxes.Box(value >= 1)); } } @@ -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)] @@ -992,7 +993,7 @@ private static void ComboBoxLoaded(object sender, RoutedEventArgs e) { if (sender is ComboBox comboBox) { - comboBox.SetValue(HasTextProperty, !string.IsNullOrWhiteSpace(comboBox.Text) || comboBox.SelectedItem != null); + comboBox.SetValue(HasTextProperty, BooleanBoxes.Box(!string.IsNullOrWhiteSpace(comboBox.Text) || comboBox.SelectedItem != null)); } } } 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 b0f48aba9a..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))] @@ -14,7 +15,7 @@ public class HotKeyBox : Control private const string PART_TextBox = "PART_TextBox"; public static readonly DependencyProperty HotKeyProperty = DependencyProperty.Register( - "HotKey", typeof(HotKey), typeof(HotKeyBox), + nameof(HotKey), typeof(HotKey), typeof(HotKeyBox), new FrameworkPropertyMetadata(default(HotKey), OnHotKeyChanged) { BindsTwoWayByDefault = true }); public HotKey HotKey @@ -30,16 +31,16 @@ private static void OnHotKeyChanged(DependencyObject d, DependencyPropertyChange } public static readonly DependencyProperty AreModifierKeysRequiredProperty = DependencyProperty.Register( - "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( - "Text", typeof(string), typeof(HotKeyBox), new PropertyMetadata(default(string))); + nameof(Text), typeof(string), typeof(HotKeyBox), new PropertyMetadata(default(string))); public static readonly DependencyProperty TextProperty = TextPropertyKey.DependencyProperty; diff --git a/src/MahApps.Metro/Controls/MetroContentControl.cs b/src/MahApps.Metro/Controls/MetroContentControl.cs index 0ae5138dfc..6341f44ddb 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() @@ -220,7 +221,7 @@ private void AfterLoadedStoryboardCurrentTimeInvalidated(object sender, System.E { if (clock.CurrentState == ClockState.Active) { - this.SetValue(IsTransitioningPropertyKey, true); + this.SetValue(IsTransitioningPropertyKey, BooleanBoxes.TrueBox); this.RaiseEvent(new RoutedEventArgs(TransitionStartedEvent)); } } @@ -234,7 +235,7 @@ private void AfterLoadedStoryboardCompleted(object sender, System.EventArgs e) } this.InvalidateVisual(); - this.SetValue(IsTransitioningPropertyKey, false); + this.SetValue(IsTransitioningPropertyKey, BooleanBoxes.FalseBox); this.RaiseEvent(new RoutedEventArgs(TransitionCompletedEvent)); } diff --git a/src/MahApps.Metro/Controls/MetroNavigationWindow.xaml.cs b/src/MahApps.Metro/Controls/MetroNavigationWindow.xaml.cs index 7140a1dfee..fd32826206 100644 --- a/src/MahApps.Metro/Controls/MetroNavigationWindow.xaml.cs +++ b/src/MahApps.Metro/Controls/MetroNavigationWindow.xaml.cs @@ -11,7 +11,7 @@ namespace MahApps.Metro.Controls /// A reimplementation of NavigationWindow based on MetroWindow. /// /// - [ContentProperty("OverlayContent")] + [ContentProperty(nameof(OverlayContent))] public partial class MetroNavigationWindow : MetroWindow, IUriContext { public MetroNavigationWindow() @@ -119,7 +119,7 @@ void PART_Frame_Navigated(object sender, NavigationEventArgs e) Navigated(this, e); } - public static readonly DependencyProperty OverlayContentProperty = DependencyProperty.Register("OverlayContent", typeof(object), typeof(MetroNavigationWindow)); + public static readonly DependencyProperty OverlayContentProperty = DependencyProperty.Register(nameof(OverlayContent), typeof(object), typeof(MetroNavigationWindow)); public object OverlayContent { @@ -127,7 +127,7 @@ public object OverlayContent set { SetValue(OverlayContentProperty, value); } } - public static readonly DependencyProperty PageContentProperty = DependencyProperty.Register("PageContent", typeof(object), typeof(MetroNavigationWindow)); + public static readonly DependencyProperty PageContentProperty = DependencyProperty.Register(nameof(PageContent), typeof(object), typeof(MetroNavigationWindow)); public object PageContent { 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 20a1f6c20d..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 { @@ -15,10 +16,10 @@ public MetroTabItem() } public static readonly DependencyProperty CloseButtonEnabledProperty = - DependencyProperty.Register("CloseButtonEnabled", + 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,11 +27,11 @@ 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 = - DependencyProperty.Register("CloseTabCommand", + DependencyProperty.Register(nameof(CloseTabCommand), typeof(ICommand), typeof(MetroTabItem)); @@ -44,7 +45,7 @@ public ICommand CloseTabCommand } public static readonly DependencyProperty CloseTabCommandParameterProperty = - DependencyProperty.Register("CloseTabCommandParameter", + DependencyProperty.Register(nameof(CloseTabCommandParameter), typeof(object), typeof(MetroTabItem), new PropertyMetadata(null)); @@ -59,7 +60,7 @@ public object CloseTabCommandParameter } public static readonly DependencyProperty CloseButtonMarginProperty = - DependencyProperty.Register("CloseButtonMargin", + DependencyProperty.Register(nameof(CloseButtonMargin), typeof(Thickness), typeof(MetroTabItem), new FrameworkPropertyMetadata(new Thickness(), FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.Inherits)); diff --git a/src/MahApps.Metro/Controls/MetroThumbContentControl.cs b/src/MahApps.Metro/Controls/MetroThumbContentControl.cs index 5ef8338a2d..46412b302f 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 { @@ -25,19 +26,19 @@ static MetroThumbContentControl() } public static readonly RoutedEvent DragStartedEvent - = EventManager.RegisterRoutedEvent("DragStarted", + = EventManager.RegisterRoutedEvent(nameof(DragStarted), RoutingStrategy.Bubble, typeof(DragStartedEventHandler), typeof(MetroThumbContentControl)); public static readonly RoutedEvent DragDeltaEvent - = EventManager.RegisterRoutedEvent("DragDelta", + = EventManager.RegisterRoutedEvent(nameof(DragDelta), RoutingStrategy.Bubble, typeof(DragDeltaEventHandler), typeof(MetroThumbContentControl)); public static readonly RoutedEvent DragCompletedEvent - = EventManager.RegisterRoutedEvent("DragCompleted", + = EventManager.RegisterRoutedEvent(nameof(DragCompleted), RoutingStrategy.Bubble, typeof(DragCompletedEventHandler), typeof(MetroThumbContentControl)); @@ -70,10 +71,10 @@ public event DragCompletedEventHandler DragCompleted } public static readonly DependencyPropertyKey IsDraggingPropertyKey - = DependencyProperty.RegisterReadOnly("IsDragging", + = 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() @@ -119,7 +120,7 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) // now capture the mouse for the drag action this.CaptureMouse(); // so now we are in dragging mode - this.SetValue(IsDraggingPropertyKey, true); + this.SetValue(IsDraggingPropertyKey, BooleanBoxes.TrueBox); // get the mouse points this.startDragPoint = e.GetPosition(this); this.oldDragScreenPoint = this.startDragScreenPoint = this.PointToScreen(this.startDragPoint); diff --git a/src/MahApps.Metro/Controls/MetroWindow.cs b/src/MahApps.Metro/Controls/MetroWindow.cs index 3638c65845..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,87 +55,87 @@ 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("ShowIconOnTitleBar", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true, OnShowIconOnTitleBarPropertyChangedCallback)); - public static readonly DependencyProperty IconEdgeModeProperty = DependencyProperty.Register("IconEdgeMode", typeof(EdgeMode), typeof(MetroWindow), new PropertyMetadata(EdgeMode.Aliased)); - public static readonly DependencyProperty IconBitmapScalingModeProperty = DependencyProperty.Register("IconBitmapScalingMode", typeof(BitmapScalingMode), typeof(MetroWindow), new PropertyMetadata(BitmapScalingMode.HighQuality)); - public static readonly DependencyProperty IconScalingModeProperty = DependencyProperty.Register("IconScalingMode", typeof(MultiFrameImageMode), typeof(MetroWindow), new FrameworkPropertyMetadata(MultiFrameImageMode.ScaleDownLargerFrame, FrameworkPropertyMetadataOptions.AffectsRender)); - public static readonly DependencyProperty ShowTitleBarProperty = DependencyProperty.Register("ShowTitleBar", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true, OnShowTitleBarPropertyChangedCallback, OnShowTitleBarCoerceValueCallback)); + public static readonly DependencyProperty 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(BooleanBoxes.TrueBox, OnShowTitleBarPropertyChangedCallback, OnShowTitleBarCoerceValueCallback)); - public static readonly DependencyProperty ShowDialogsOverTitleBarProperty = DependencyProperty.Register("ShowDialogsOverTitleBar", typeof(bool), typeof(MetroWindow), new FrameworkPropertyMetadata(true, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender)); + public static readonly 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("ShowMinButton", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty ShowMaxRestoreButtonProperty = DependencyProperty.Register("ShowMaxRestoreButton", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty ShowCloseButtonProperty = DependencyProperty.Register("ShowCloseButton", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly DependencyProperty 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("IsMinButtonEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty IsMaxRestoreButtonEnabledProperty = DependencyProperty.Register("IsMaxRestoreButtonEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty IsCloseButtonEnabledProperty = DependencyProperty.Register("IsCloseButtonEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly 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("ShowSystemMenu", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty ShowSystemMenuOnRightClickProperty = DependencyProperty.Register("ShowSystemMenuOnRightClick", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); + public static readonly DependencyProperty 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("TitleBarHeight", typeof(int), typeof(MetroWindow), new PropertyMetadata(30, TitleBarHeightPropertyChangedCallback)); - public static readonly DependencyProperty TitleCharacterCasingProperty = DependencyProperty.Register("TitleCharacterCasing", typeof(CharacterCasing), typeof(MetroWindow), new FrameworkPropertyMetadata(CharacterCasing.Upper, FrameworkPropertyMetadataOptions.Inherits | FrameworkPropertyMetadataOptions.AffectsMeasure), value => CharacterCasing.Normal <= (CharacterCasing)value && (CharacterCasing)value <= CharacterCasing.Upper); - public static readonly DependencyProperty TitleAlignmentProperty = DependencyProperty.Register("TitleAlignment", typeof(HorizontalAlignment), typeof(MetroWindow), new PropertyMetadata(HorizontalAlignment.Stretch, OnTitleAlignmentChanged)); + public static readonly DependencyProperty 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("SaveWindowPosition", typeof(bool), typeof(MetroWindow), new PropertyMetadata(false)); - public static readonly DependencyProperty WindowPlacementSettingsProperty = DependencyProperty.Register("WindowPlacementSettings", typeof(IWindowPlacementSettings), typeof(MetroWindow), new PropertyMetadata(null)); - public static readonly DependencyProperty TitleForegroundProperty = DependencyProperty.Register("TitleForeground", typeof(Brush), typeof(MetroWindow)); - public static readonly DependencyProperty FlyoutsProperty = DependencyProperty.Register("Flyouts", typeof(FlyoutsControl), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds)); - public static readonly DependencyProperty WindowTransitionsEnabledProperty = DependencyProperty.Register("WindowTransitionsEnabled", typeof(bool), typeof(MetroWindow), new PropertyMetadata(true)); - public static readonly DependencyProperty MetroDialogOptionsProperty = DependencyProperty.Register("MetroDialogOptions", typeof(MetroDialogSettings), typeof(MetroWindow), new PropertyMetadata(default(MetroDialogSettings))); + public static readonly DependencyProperty 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(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("WindowTitleBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Transparent)); - public static readonly DependencyProperty NonActiveWindowTitleBrushProperty = DependencyProperty.Register("NonActiveWindowTitleBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Gray)); - public static readonly DependencyProperty NonActiveBorderBrushProperty = DependencyProperty.Register("NonActiveBorderBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Gray)); + public static readonly DependencyProperty WindowTitleBrushProperty = DependencyProperty.Register(nameof(WindowTitleBrush), typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Transparent)); + public static readonly DependencyProperty NonActiveWindowTitleBrushProperty = DependencyProperty.Register(nameof(NonActiveWindowTitleBrush), typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Gray)); + public static readonly DependencyProperty NonActiveBorderBrushProperty = DependencyProperty.Register(nameof(NonActiveBorderBrush), typeof(Brush), typeof(MetroWindow), new PropertyMetadata(Brushes.Gray)); - public static readonly DependencyProperty GlowBrushProperty = DependencyProperty.Register("GlowBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null)); - public static readonly DependencyProperty NonActiveGlowBrushProperty = DependencyProperty.Register("NonActiveGlowBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null)); + public static readonly DependencyProperty GlowBrushProperty = DependencyProperty.Register(nameof(GlowBrush), typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null)); + public static readonly DependencyProperty NonActiveGlowBrushProperty = DependencyProperty.Register(nameof(NonActiveGlowBrush), typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null)); - public static readonly DependencyProperty OverlayBrushProperty = DependencyProperty.Register("OverlayBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null)); - public static readonly DependencyProperty OverlayOpacityProperty = DependencyProperty.Register("OverlayOpacity", typeof(double), typeof(MetroWindow), new PropertyMetadata(0.7d)); + public static readonly DependencyProperty OverlayBrushProperty = DependencyProperty.Register(nameof(OverlayBrush), typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null)); + public static readonly DependencyProperty OverlayOpacityProperty = DependencyProperty.Register(nameof(OverlayOpacity), typeof(double), typeof(MetroWindow), new PropertyMetadata(0.7d)); - public static readonly DependencyProperty FlyoutOverlayBrushProperty = DependencyProperty.Register("FlyoutOverlayBrush", typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null)); + public static readonly DependencyProperty FlyoutOverlayBrushProperty = DependencyProperty.Register(nameof(FlyoutOverlayBrush), typeof(Brush), typeof(MetroWindow), new PropertyMetadata(null)); /// /// Identifies the dependency property. /// - public static readonly DependencyProperty OverlayFadeInProperty = DependencyProperty.Register("OverlayFadeIn", typeof(Storyboard), typeof(MetroWindow), new PropertyMetadata(default(Storyboard))); + public static readonly DependencyProperty OverlayFadeInProperty = DependencyProperty.Register(nameof(OverlayFadeIn), typeof(Storyboard), typeof(MetroWindow), new PropertyMetadata(default(Storyboard))); /// /// Identifies the dependency property. /// - public static readonly DependencyProperty OverlayFadeOutProperty = DependencyProperty.Register("OverlayFadeOut", typeof(Storyboard), typeof(MetroWindow), new PropertyMetadata(default(Storyboard))); + public static readonly DependencyProperty OverlayFadeOutProperty = DependencyProperty.Register(nameof(OverlayFadeOut), typeof(Storyboard), typeof(MetroWindow), new PropertyMetadata(default(Storyboard))); - public static readonly DependencyProperty IconTemplateProperty = DependencyProperty.Register("IconTemplate", typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null)); - public static readonly DependencyProperty TitleTemplateProperty = DependencyProperty.Register("TitleTemplate", typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null)); + public static readonly DependencyProperty IconTemplateProperty = DependencyProperty.Register(nameof(IconTemplate), typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null)); + public static readonly DependencyProperty TitleTemplateProperty = DependencyProperty.Register(nameof(TitleTemplate), typeof(DataTemplate), typeof(MetroWindow), new PropertyMetadata(null)); - public static readonly DependencyProperty LeftWindowCommandsProperty = DependencyProperty.Register("LeftWindowCommands", typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds)); - public static readonly DependencyProperty RightWindowCommandsProperty = DependencyProperty.Register("RightWindowCommands", typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds)); - public static readonly DependencyProperty WindowButtonCommandsProperty = DependencyProperty.Register("WindowButtonCommands", typeof(WindowButtonCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds)); + public static readonly DependencyProperty LeftWindowCommandsProperty = DependencyProperty.Register(nameof(LeftWindowCommands), typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds)); + public static readonly DependencyProperty RightWindowCommandsProperty = DependencyProperty.Register(nameof(RightWindowCommands), typeof(WindowCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds)); + public static readonly DependencyProperty WindowButtonCommandsProperty = DependencyProperty.Register(nameof(WindowButtonCommands), typeof(WindowButtonCommands), typeof(MetroWindow), new PropertyMetadata(null, UpdateLogicalChilds)); - public static readonly DependencyProperty LeftWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("LeftWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Never, OnShowTitleBarPropertyChangedCallback)); - public static readonly DependencyProperty RightWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register("RightWindowCommandsOverlayBehavior", typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Never, OnShowTitleBarPropertyChangedCallback)); - public static readonly DependencyProperty WindowButtonCommandsOverlayBehaviorProperty = DependencyProperty.Register("WindowButtonCommandsOverlayBehavior", typeof(OverlayBehavior), typeof(MetroWindow), new PropertyMetadata(OverlayBehavior.Always, OnShowTitleBarPropertyChangedCallback)); - public static readonly DependencyProperty IconOverlayBehaviorProperty = DependencyProperty.Register("IconOverlayBehavior", typeof(OverlayBehavior), typeof(MetroWindow), new PropertyMetadata(OverlayBehavior.Never, OnShowTitleBarPropertyChangedCallback)); + public static readonly DependencyProperty LeftWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register(nameof(LeftWindowCommandsOverlayBehavior), typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Never, OnShowTitleBarPropertyChangedCallback)); + public static readonly DependencyProperty RightWindowCommandsOverlayBehaviorProperty = DependencyProperty.Register(nameof(RightWindowCommandsOverlayBehavior), typeof(WindowCommandsOverlayBehavior), typeof(MetroWindow), new PropertyMetadata(WindowCommandsOverlayBehavior.Never, OnShowTitleBarPropertyChangedCallback)); + 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("UseNoneWindowStyle", typeof(bool), typeof(MetroWindow), new PropertyMetadata(false, OnUseNoneWindowStylePropertyChangedCallback)); - public static readonly DependencyProperty OverrideDefaultWindowCommandsBrushProperty = DependencyProperty.Register("OverrideDefaultWindowCommandsBrush", typeof(Brush), typeof(MetroWindow)); + 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("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; @@ -153,7 +154,7 @@ public class MetroWindow : Window Rectangle flyoutModal; public static readonly RoutedEvent FlyoutsStatusChangedEvent = EventManager.RegisterRoutedEvent( - "FlyoutsStatusChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MetroWindow)); + nameof(FlyoutsStatusChanged), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MetroWindow)); // Provide CLR accessors for the event public event RoutedEventHandler FlyoutsStatusChanged @@ -162,7 +163,7 @@ public event RoutedEventHandler FlyoutsStatusChanged remove { RemoveHandler(FlyoutsStatusChangedEvent, value); } } - public static readonly RoutedEvent WindowTransitionCompletedEvent = EventManager.RegisterRoutedEvent("WindowTransitionCompleted", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MetroWindow)); + public static readonly RoutedEvent WindowTransitionCompletedEvent = EventManager.RegisterRoutedEvent(nameof(WindowTransitionCompleted), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(MetroWindow)); public event RoutedEventHandler WindowTransitionCompleted { @@ -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/MultiFrameImage.cs b/src/MahApps.Metro/Controls/MultiFrameImage.cs index a417fc0582..1d6dcf21de 100644 --- a/src/MahApps.Metro/Controls/MultiFrameImage.cs +++ b/src/MahApps.Metro/Controls/MultiFrameImage.cs @@ -16,7 +16,7 @@ static MultiFrameImage() } public static readonly DependencyProperty MultiFrameImageModeProperty = DependencyProperty.Register( - "MultiFrameImageMode", typeof(MultiFrameImageMode), typeof(MultiFrameImage), new FrameworkPropertyMetadata(MultiFrameImageMode.ScaleDownLargerFrame, FrameworkPropertyMetadataOptions.AffectsRender)); + nameof(MultiFrameImageMode), typeof(MultiFrameImageMode), typeof(MultiFrameImage), new FrameworkPropertyMetadata(MultiFrameImageMode.ScaleDownLargerFrame, FrameworkPropertyMetadataOptions.AffectsRender)); public MultiFrameImageMode MultiFrameImageMode { get { return (MultiFrameImageMode)GetValue(MultiFrameImageModeProperty); } 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/Pivot.cs b/src/MahApps.Metro/Controls/Pivot.cs index 68f21b900b..5a11179321 100644 --- a/src/MahApps.Metro/Controls/Pivot.cs +++ b/src/MahApps.Metro/Controls/Pivot.cs @@ -15,10 +15,10 @@ public class Pivot : ItemsControl private PivotItem selectedItem; private ScrollViewerOffsetMediator mediator; internal int internalIndex; - public static readonly RoutedEvent SelectionChangedEvent = EventManager.RegisterRoutedEvent("SelectionChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Pivot)); - public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof(string), typeof(Pivot), new PropertyMetadata(default(string))); - public static readonly DependencyProperty HeaderTemplateProperty = DependencyProperty.Register("HeaderTemplate", typeof(DataTemplate), typeof(Pivot)); - public static readonly DependencyProperty SelectedIndexProperty = DependencyProperty.Register("SelectedIndex", typeof(int), typeof(Pivot), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, SelectedItemChanged)); + public static readonly RoutedEvent SelectionChangedEvent = EventManager.RegisterRoutedEvent(nameof(SelectionChanged), RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(Pivot)); + public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(string), typeof(Pivot), new PropertyMetadata(default(string))); + public static readonly DependencyProperty HeaderTemplateProperty = DependencyProperty.Register(nameof(HeaderTemplate), typeof(DataTemplate), typeof(Pivot)); + public static readonly DependencyProperty SelectedIndexProperty = DependencyProperty.Register(nameof(SelectedIndex), typeof(int), typeof(Pivot), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, SelectedItemChanged)); public DataTemplate HeaderTemplate { diff --git a/src/MahApps.Metro/Controls/PivotItem.cs b/src/MahApps.Metro/Controls/PivotItem.cs index d887b0d5f7..9f534ba26c 100644 --- a/src/MahApps.Metro/Controls/PivotItem.cs +++ b/src/MahApps.Metro/Controls/PivotItem.cs @@ -5,7 +5,7 @@ namespace MahApps.Metro.Controls { public class PivotItem : ContentControl { - public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof(string), typeof(PivotItem), new PropertyMetadata(default(string))); + public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(nameof(Header), typeof(string), typeof(PivotItem), new PropertyMetadata(default(string))); public string Header { diff --git a/src/MahApps.Metro/Controls/Planerator.cs b/src/MahApps.Metro/Controls/Planerator.cs index f3b44f6007..b99723007c 100644 --- a/src/MahApps.Metro/Controls/Planerator.cs +++ b/src/MahApps.Metro/Controls/Planerator.cs @@ -11,7 +11,7 @@ namespace MahApps.Metro.Controls /// Based on Greg Schechter's Planerator /// http://blogs.msdn.com/b/greg_schechter/archive/2007/10/26/enter-the-planerator-dead-simple-3d-in-wpf-with-a-stupid-name.aspx /// - [ContentProperty("Child")] + [ContentProperty(nameof(Child))] public class Planerator : FrameworkElement { /// 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/RevealImage.xaml.cs b/src/MahApps.Metro/Controls/RevealImage.xaml.cs index 33d9e459c4..adcfe02a87 100644 --- a/src/MahApps.Metro/Controls/RevealImage.xaml.cs +++ b/src/MahApps.Metro/Controls/RevealImage.xaml.cs @@ -9,8 +9,8 @@ namespace MahApps.Metro.Controls { public partial class RevealImage : UserControl { - public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(RevealImage), new UIPropertyMetadata("")); - public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(ImageSource), typeof(RevealImage), new UIPropertyMetadata(null)); + public static readonly DependencyProperty TextProperty = DependencyProperty.Register(nameof(Text), typeof(string), typeof(RevealImage), new UIPropertyMetadata("")); + public static readonly DependencyProperty ImageProperty = DependencyProperty.Register(nameof(Image), typeof(ImageSource), typeof(RevealImage), new UIPropertyMetadata(null)); public string Text { diff --git a/src/MahApps.Metro/Controls/ScrollViewerOffsetMediator.cs b/src/MahApps.Metro/Controls/ScrollViewerOffsetMediator.cs index eefe879a78..3788cd3f16 100644 --- a/src/MahApps.Metro/Controls/ScrollViewerOffsetMediator.cs +++ b/src/MahApps.Metro/Controls/ScrollViewerOffsetMediator.cs @@ -5,8 +5,8 @@ namespace MahApps.Metro.Controls { public class ScrollViewerOffsetMediator : FrameworkElement { - public static readonly DependencyProperty ScrollViewerProperty = DependencyProperty.Register("ScrollViewer", typeof(ScrollViewer), typeof(ScrollViewerOffsetMediator), new PropertyMetadata(default(ScrollViewer), OnScrollViewerChanged)); - public static readonly DependencyProperty HorizontalOffsetProperty = DependencyProperty.Register("HorizontalOffset", typeof(double), typeof(ScrollViewerOffsetMediator), new PropertyMetadata(default(double), OnHorizontalOffsetChanged)); + public static readonly DependencyProperty ScrollViewerProperty = DependencyProperty.Register(nameof(ScrollViewer), typeof(ScrollViewer), typeof(ScrollViewerOffsetMediator), new PropertyMetadata(default(ScrollViewer), OnScrollViewerChanged)); + public static readonly DependencyProperty HorizontalOffsetProperty = DependencyProperty.Register(nameof(HorizontalOffset), typeof(double), typeof(ScrollViewerOffsetMediator), new PropertyMetadata(default(double), OnHorizontalOffsetChanged)); public ScrollViewer ScrollViewer { 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 223af51afc..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 { @@ -12,7 +13,7 @@ static Tile() DefaultStyleKeyProperty.OverrideMetadata(typeof(Tile), new FrameworkPropertyMetadata(typeof(Tile))); } - public static readonly DependencyProperty TitleProperty = DependencyProperty.Register("Title", typeof(string), typeof(Tile), new PropertyMetadata(default(string))); + public static readonly DependencyProperty TitleProperty = DependencyProperty.Register(nameof(Title), typeof(string), typeof(Tile), new PropertyMetadata(default(string))); public string Title { @@ -26,7 +27,7 @@ public string Title /// public static readonly DependencyProperty HorizontalTitleAlignmentProperty = DependencyProperty.Register( - "HorizontalTitleAlignment", + nameof(HorizontalTitleAlignment), typeof(HorizontalAlignment), typeof(Tile), new FrameworkPropertyMetadata(HorizontalAlignment.Left)); @@ -47,7 +48,7 @@ public HorizontalAlignment HorizontalTitleAlignment /// public static readonly DependencyProperty VerticalTitleAlignmentProperty = DependencyProperty.Register( - "VerticalTitleAlignment", + nameof(VerticalTitleAlignment), typeof(VerticalAlignment), typeof(Tile), new FrameworkPropertyMetadata(VerticalAlignment.Bottom)); @@ -62,7 +63,7 @@ public VerticalAlignment VerticalTitleAlignment set { SetValue(VerticalTitleAlignmentProperty, value); } } - public static readonly DependencyProperty CountProperty = DependencyProperty.Register("Count", typeof(string), typeof(Tile), new PropertyMetadata(default(string))); + public static readonly DependencyProperty CountProperty = DependencyProperty.Register(nameof(Count), typeof(string), typeof(Tile), new PropertyMetadata(default(string))); public string Count { @@ -70,15 +71,15 @@ public string Count set { SetValue(CountProperty, value); } } - public static readonly DependencyProperty KeepDraggingProperty = DependencyProperty.Register("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("TiltFactor", typeof(int), typeof(Tile), new PropertyMetadata(5)); + public static readonly DependencyProperty TiltFactorProperty = DependencyProperty.Register(nameof(TiltFactor), typeof(int), typeof(Tile), new PropertyMetadata(5)); public int TiltFactor { @@ -86,7 +87,7 @@ public int TiltFactor set { SetValue(TiltFactorProperty, value); } } - public static readonly DependencyProperty TitleFontSizeProperty = DependencyProperty.Register("TitleFontSize", typeof(double), typeof(Tile), new PropertyMetadata(16d)); + public static readonly DependencyProperty TitleFontSizeProperty = DependencyProperty.Register(nameof(TitleFontSize), typeof(double), typeof(Tile), new PropertyMetadata(16d)); public double TitleFontSize { @@ -94,7 +95,7 @@ public double TitleFontSize set { SetValue(TitleFontSizeProperty, value); } } - public static readonly DependencyProperty CountFontSizeProperty = DependencyProperty.Register("CountFontSize", typeof(double), typeof(Tile), new PropertyMetadata(28d)); + public static readonly DependencyProperty CountFontSizeProperty = DependencyProperty.Register(nameof(CountFontSize), typeof(double), typeof(Tile), new PropertyMetadata(28d)); public double CountFontSize { diff --git a/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs b/src/MahApps.Metro/Controls/TimePicker/DateTimePicker.cs index a777316914..4097c2683b 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 { @@ -86,7 +87,7 @@ public DayOfWeek FirstDayOfWeek public bool IsTodayHighlighted { get => (bool)this.GetValue(IsTodayHighlightedProperty); - set => this.SetValue(IsTodayHighlightedProperty, value); + set => this.SetValue(IsTodayHighlightedProperty, BooleanBoxes.Box(value)); } /// Identifies the dependency property. @@ -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..e7eb1a5b61 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 { @@ -160,7 +161,7 @@ public IEnumerable SourceSeconds /// Identifies the dependency property. public static readonly DependencyProperty IsDropDownOpenProperty = DatePicker.IsDropDownOpenProperty.AddOwner(typeof(TimePickerBase), - new FrameworkPropertyMetadata(default(bool), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsDropDownOpenChanged, OnCoerceIsDropDownOpen)); + new FrameworkPropertyMetadata(BooleanBoxes.FalseBox, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsDropDownOpenChanged, OnCoerceIsDropDownOpen)); /// /// Gets or sets a value indicating whether the drop-down for a box is currently @@ -170,7 +171,7 @@ public static readonly DependencyProperty IsDropDownOpenProperty public bool IsDropDownOpen { get => (bool)this.GetValue(IsDropDownOpenProperty); - set => this.SetValue(IsDropDownOpenProperty, value); + set => this.SetValue(IsDropDownOpenProperty, BooleanBoxes.Box(value)); } private static object OnCoerceIsDropDownOpen(DependencyObject d, object baseValue) @@ -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 091a576679..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,11 +77,11 @@ public class TransitioningContentControl : ContentControl public const TransitionType DefaultTransitionState = TransitionType.Default; - public static readonly DependencyProperty IsTransitioningProperty = DependencyProperty.Register("IsTransitioning", typeof(bool), typeof(TransitioningContentControl), new PropertyMetadata(OnIsTransitioningPropertyChanged)); - public static readonly DependencyProperty TransitionProperty = DependencyProperty.Register("Transition", typeof(TransitionType), typeof(TransitioningContentControl), new FrameworkPropertyMetadata(TransitionType.Default, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.Inherits, OnTransitionPropertyChanged)); - public static readonly DependencyProperty RestartTransitionOnContentChangeProperty = DependencyProperty.Register("RestartTransitionOnContentChange", typeof(bool), typeof(TransitioningContentControl), new PropertyMetadata(false, OnRestartTransitionOnContentChangePropertyChanged)); - public static readonly DependencyProperty CustomVisualStatesProperty = DependencyProperty.Register("CustomVisualStates", typeof(ObservableCollection), typeof(TransitioningContentControl), new PropertyMetadata(null)); - public static readonly DependencyProperty CustomVisualStatesNameProperty = DependencyProperty.Register("CustomVisualStatesName", typeof(string), typeof(TransitioningContentControl), new PropertyMetadata("CustomTransition")); + 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(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")); public ObservableCollection CustomVisualStates { @@ -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 c1aebf812e..2b129ec4fb 100644 --- a/src/MahApps.Metro/Controls/WindowCommands.cs +++ b/src/MahApps.Metro/Controls/WindowCommands.cs @@ -8,10 +8,11 @@ using System.Windows.Data; using ControlzEx; using ControlzEx.Theming; +using MahApps.Metro.ValueBoxes; namespace MahApps.Metro.Controls { - [StyleTypedProperty(Property = "ItemContainerStyle", StyleTargetType = typeof(WindowCommands))] + [StyleTypedProperty(Property = nameof(ItemContainerStyle), StyleTargetType = typeof(WindowCommands))] public class WindowCommands : ToolBar { /// Identifies the dependency property. @@ -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. 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