From 6d9cb88951933c79a47515851c3339e769cf91aa Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 8 Jul 2023 01:15:21 +0800 Subject: [PATCH 1/4] make mothed protect for sub-class --- source/NumericUpDownLib/Base/AbstractBaseUpDown.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs b/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs index 1ab156b..c742a4b 100644 --- a/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs +++ b/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs @@ -325,7 +325,7 @@ public IInputElement CommandTarget /// (supporting and bindings) /// /// - private void CommandExecute(ICommand cmd) + protected void CommandExecute(ICommand cmd) { if (cmd is RoutedCommand command) command.Execute(CommandParameter, CommandTarget); @@ -340,7 +340,7 @@ private void CommandExecute(ICommand cmd) /// /// /// - private void HookUpCommand(ICommand oldCommand, ICommand newCommand) + protected void HookUpCommand(ICommand oldCommand, ICommand newCommand) { if (oldCommand != null) { @@ -359,7 +359,7 @@ private void HookUpCommand(ICommand oldCommand, ICommand newCommand) /// /// /// - private void CanExecuteChanged(object sender, EventArgs e) + protected void CanExecuteChanged(object sender, EventArgs e) { if (this.Command is RoutedCommand command) { From b2362894c7d80f0092672661c888ad1304e001e0 Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 8 Jul 2023 01:29:07 +0800 Subject: [PATCH 2/4] format the file code using all tab --- .../Base/AbstractBaseUpDown.cs | 202 +++++++++--------- 1 file changed, 101 insertions(+), 101 deletions(-) diff --git a/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs b/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs index c742a4b..378511e 100644 --- a/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs +++ b/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs @@ -176,15 +176,15 @@ public abstract partial class AbstractBaseUpDown : InputBaseUpDown, ICommandS DependencyProperty.Register("CanMouseDrag", typeof(CanIncDecMouseDrag), typeof(AbstractBaseUpDown), new PropertyMetadata(CanIncDecMouseDrag.VerticalHorizontal)); - public static readonly DependencyProperty MouseWheelEnabledProperty = - DependencyProperty.Register("MouseWheelEnabled", typeof(bool), - typeof(AbstractBaseUpDown), - new PropertyMetadata(true)); - - /// - /// Backing store of dependency property. - /// - public static readonly DependencyProperty IsLargeStepEnabledProperty = + public static readonly DependencyProperty MouseWheelEnabledProperty = + DependencyProperty.Register("MouseWheelEnabled", typeof(bool), + typeof(AbstractBaseUpDown), + new PropertyMetadata(true)); + + /// + /// Backing store of dependency property. + /// + public static readonly DependencyProperty IsLargeStepEnabledProperty = DependencyProperty.Register("IsLargeStepEnabled", typeof(bool), typeof(AbstractBaseUpDown), new PropertyMetadata(true)); @@ -442,23 +442,23 @@ public byte DisplayLength set { SetValue(DisplayLengthProperty, value); } } - /// - /// Gets/sets the MinWidth for the control. The width of the textbox portion of - /// the control is expanded to fill the MinWidth value while the width of the + /// + /// Gets/sets the MinWidth for the control. The width of the textbox portion of + /// the control is expanded to fill the MinWidth value while the width of the /// UpDown buttons are auto sized. - /// - public virtual double MinWidth + /// + public virtual double MinWidth { get { return (double)GetValue(MinWidthProperty); } set { SetValue(MinWidthProperty, value); } } - /// - /// Gets/sets whether the textbox portion of the numeric up down control - /// can go grow and shrink with its input or whether it should stay with - /// a fixed width. - /// - public bool IsDisplayLengthFixed + /// + /// Gets/sets whether the textbox portion of the numeric up down control + /// can go grow and shrink with its input or whether it should stay with + /// a fixed width. + /// + public bool IsDisplayLengthFixed { get { return (bool)GetValue(IsDisplayLengthFixedProperty); } set { SetValue(IsDisplayLengthFixedProperty, value); } @@ -530,16 +530,16 @@ public CanIncDecMouseDrag CanMouseDrag set { SetValue(CanMouseDragProperty, value); } } - public bool MouseWheelEnabled - { - get { return (bool)GetValue(MouseWheelEnabledProperty); } - set { SetValue(MouseWheelEnabledProperty, value); } - } + public bool MouseWheelEnabled + { + get { return (bool)GetValue(MouseWheelEnabledProperty); } + set { SetValue(MouseWheelEnabledProperty, value); } + } - /// - /// Gets/sets wether enable large step Increment/Decrement - /// - public bool IsLargeStepEnabled + /// + /// Gets/sets wether enable large step Increment/Decrement + /// + public bool IsLargeStepEnabled { get { return (bool)GetValue(IsLargeStepEnabledProperty); } set { SetValue(IsLargeStepEnabledProperty, value); } @@ -679,9 +679,9 @@ protected override void OnMouseWheel(MouseWheelEventArgs e) { base.OnMouseWheel(e); - if (!MouseWheelEnabled) - return; - if (e.Handled == false) + if (!MouseWheelEnabled) + return; + if (e.Handled == false) { if (e.Delta != 0) { @@ -716,14 +716,14 @@ protected override void OnMouseWheel(MouseWheelEventArgs e) } } - #region IsMouseDragEnabled - /// - /// Is invoked when dependency property value - /// has been changed to update all states accordingly. - /// - /// - /// - private static void OnIsMouseDragEnabledChanged(DependencyObject d, + #region IsMouseDragEnabled + /// + /// Is invoked when dependency property value + /// has been changed to update all states accordingly. + /// + /// + /// + private static void OnIsMouseDragEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { (d as AbstractBaseUpDown).OnIsMouseDragEnabledChanged(e); @@ -1148,67 +1148,67 @@ private bool IsModifierKeyDown() } - /// - /// Gets a formatted string for the value of the number passed in - /// and ensures that a default string is returned even if there is - /// no format specified. - /// - /// .Net type specific value to be formated as string - /// The string that was formatted with the FormatString - /// dependency property - protected string FormatNumber(T number) - { - string format = "{0}"; - var form = (string) GetValue(FormatStringProperty); - if (string.IsNullOrEmpty(this.FormatString) == false) - { - format = !FormatString.StartsWith("{") - ? "{0:" + this.FormatString + "}" - : FormatString; - } - - return string.Format(format, number); - } - - /// - /// Checks if the current string entered in the textbox is: - /// 1) A valid number (syntax) - /// 2) within bounds (Min <= number <= Max ) - /// - /// 3) adjusts the string if it appears to be invalid and - /// - /// 4) true: - /// Applies the FormatString property to format the text in a certain way - /// - /// - /// - /// the value of the string with special format - protected T FormatText(string text, bool formatNumber = true) - { - if (_PART_TextBox == null) - return Value; - - T number = default; - // Does this text represent a valid number ? - if (ParseText(text, out number)) - { - number = CoerceValue(number); - - _PART_TextBox.Text = FormatNumber(number); - _PART_TextBox.SelectionStart = 0; - - return number; - } - - // Reset to last value since string does not appear to represent a number - _PART_TextBox.SelectionStart = 0; - _PART_TextBox.Text = FormatNumber(Value); - return LastEditingNumericValue; - } - - protected abstract bool ParseText(string text, out T number); - - /// + /// + /// Gets a formatted string for the value of the number passed in + /// and ensures that a default string is returned even if there is + /// no format specified. + /// + /// .Net type specific value to be formated as string + /// The string that was formatted with the FormatString + /// dependency property + protected string FormatNumber(T number) + { + string format = "{0}"; + var form = (string) GetValue(FormatStringProperty); + if (string.IsNullOrEmpty(this.FormatString) == false) + { + format = !FormatString.StartsWith("{") + ? "{0:" + this.FormatString + "}" + : FormatString; + } + + return string.Format(format, number); + } + + /// + /// Checks if the current string entered in the textbox is: + /// 1) A valid number (syntax) + /// 2) within bounds (Min <= number <= Max ) + /// + /// 3) adjusts the string if it appears to be invalid and + /// + /// 4) true: + /// Applies the FormatString property to format the text in a certain way + /// + /// + /// + /// the value of the string with special format + protected T FormatText(string text, bool formatNumber = true) + { + if (_PART_TextBox == null) + return Value; + + T number = default; + // Does this text represent a valid number ? + if (ParseText(text, out number)) + { + number = CoerceValue(number); + + _PART_TextBox.Text = FormatNumber(number); + _PART_TextBox.SelectionStart = 0; + + return number; + } + + // Reset to last value since string does not appear to represent a number + _PART_TextBox.SelectionStart = 0; + _PART_TextBox.Text = FormatNumber(Value); + return LastEditingNumericValue; + } + + protected abstract bool ParseText(string text, out T number); + + /// /// Verify the text is valid or not while use is typing /// /// From 15b7ee3b6b6c63dc4308be2e650480fff8d4d3cc Mon Sep 17 00:00:00 2001 From: heartacker Date: Sat, 8 Jul 2023 18:41:32 +0800 Subject: [PATCH 3/4] fix IDE warning --- source/NumericUpDownLib/Base/InputBaseUpDown.xaml.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/NumericUpDownLib/Base/InputBaseUpDown.xaml.cs b/source/NumericUpDownLib/Base/InputBaseUpDown.xaml.cs index 9e45563..6ee063a 100644 --- a/source/NumericUpDownLib/Base/InputBaseUpDown.xaml.cs +++ b/source/NumericUpDownLib/Base/InputBaseUpDown.xaml.cs @@ -51,20 +51,20 @@ public abstract class InputBaseUpDown : Control /// identify that the inputing data is valid or not., /// /// - protected System.Windows.Media.SolidColorBrush EditingColorBrush + public System.Windows.Media.SolidColorBrush EditingColorBrush { get { return (System.Windows.Media.SolidColorBrush)GetValue(EditingColorBrushProperty); } - set { SetValue(EditingColorBrushProperty, value); } + protected set { SetValue(EditingColorBrushProperty, value); } } /// /// identify that the editing Visibility /// /// - protected Visibility EditingVisibility + public Visibility EditingVisibility { get { return (Visibility)GetValue(EditingVisibilityProperty); } - set { SetValue(EditingVisibilityProperty, value); } + protected set { SetValue(EditingVisibilityProperty, value); } } /// From c16a94ebb0d2a91fbc59ad30698775003b20fe2f Mon Sep 17 00:00:00 2001 From: heartacker Date: Sun, 9 Jul 2023 09:27:12 +0800 Subject: [PATCH 4/4] public some Property --- .../Base/AbstractBaseUpDown.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs b/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs index 378511e..6ab6c0f 100644 --- a/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs +++ b/source/NumericUpDownLib/Base/AbstractBaseUpDown.cs @@ -68,7 +68,7 @@ public abstract partial class AbstractBaseUpDown : InputBaseUpDown, ICommandS /// /// Dependency property backing store for the Value property. defalut value is _MinValue /// - protected static readonly DependencyProperty ValueProperty = + public static readonly DependencyProperty ValueProperty = DependencyProperty.Register("Value", typeof(T), typeof(AbstractBaseUpDown), new PropertyMetadata(_MinValue, new PropertyChangedCallback(OnValueChanged), @@ -77,7 +77,7 @@ public abstract partial class AbstractBaseUpDown : InputBaseUpDown, ICommandS /// /// Dependency property backing store for Minimum Value property. /// - protected static readonly DependencyProperty MinValueProperty = + public static readonly DependencyProperty MinValueProperty = DependencyProperty.Register("MinValue", typeof(T), typeof(AbstractBaseUpDown), new PropertyMetadata(_MinValue, new PropertyChangedCallback(OnMinValueChanged), @@ -86,7 +86,7 @@ public abstract partial class AbstractBaseUpDown : InputBaseUpDown, ICommandS /// /// Dependency property backing store for Maximum Value property. /// - protected static readonly DependencyProperty MaxValueProperty = + public static readonly DependencyProperty MaxValueProperty = DependencyProperty.Register("MaxValue", typeof(T), typeof(AbstractBaseUpDown), new PropertyMetadata(_MaxValue, new PropertyChangedCallback(OnMaxValueChanged), @@ -124,7 +124,7 @@ public abstract partial class AbstractBaseUpDown : InputBaseUpDown, ICommandS /// that should be displayed in the control without having to scroll inside /// the textbox portion. /// - protected static readonly DependencyProperty DisplayLengthProperty = + public static readonly DependencyProperty DisplayLengthProperty = DependencyProperty.Register("DisplayLength", typeof(byte), typeof(AbstractBaseUpDown), new PropertyMetadata((byte)3)); @@ -134,7 +134,7 @@ public abstract partial class AbstractBaseUpDown : InputBaseUpDown, ICommandS /// if user types longer string), or not (control will resize in dependence /// of string length and available space). /// - protected static readonly DependencyProperty IsDisplayLengthFixedProperty = + public static readonly DependencyProperty IsDisplayLengthFixedProperty = DependencyProperty.Register("IsDisplayLengthFixed", typeof(bool), typeof(AbstractBaseUpDown), new PropertyMetadata(true, OnIsDisplayLengthFixedChanged)); @@ -142,7 +142,7 @@ public abstract partial class AbstractBaseUpDown : InputBaseUpDown, ICommandS /// Backing store for dependency property to decide whether all text in textbox /// should be selected upon focus or not. /// - protected static readonly DependencyProperty SelectAllTextOnFocusProperty = + public static readonly DependencyProperty SelectAllTextOnFocusProperty = DependencyProperty.Register("SelectAllTextOnFocus", typeof(bool), typeof(AbstractBaseUpDown), new PropertyMetadata(true)); @@ -150,7 +150,7 @@ public abstract partial class AbstractBaseUpDown : InputBaseUpDown, ICommandS /// Backing store for dependency property for .Net FormatString that is /// applied to the textbox text portion of the up down control. /// - protected static readonly DependencyProperty FormatStringProperty = + public static readonly DependencyProperty FormatStringProperty = DependencyProperty.Register("FormatString", typeof(string), typeof(AbstractBaseUpDown), new PropertyMetadata("G", OnIsFormatStringChanged)); @@ -600,7 +600,7 @@ protected set /// /// Determines whether last text input was from a user (key was down) or not. /// - protected bool UserInput { get; set; } + public bool UserInput { get; protected set; } #endregion properties #region methods @@ -1159,7 +1159,7 @@ private bool IsModifierKeyDown() protected string FormatNumber(T number) { string format = "{0}"; - var form = (string) GetValue(FormatStringProperty); + var form = (string)GetValue(FormatStringProperty); if (string.IsNullOrEmpty(this.FormatString) == false) { format = !FormatString.StartsWith("{")