Skip to content

Command_protect #64

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 111 additions & 111 deletions source/NumericUpDownLib/Base/AbstractBaseUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public abstract partial class AbstractBaseUpDown<T> : InputBaseUpDown, ICommandS
/// <summary>
/// Dependency property backing store for the Value property. defalut value is _MinValue
/// </summary>
protected static readonly DependencyProperty ValueProperty =
public static readonly DependencyProperty ValueProperty =
DependencyProperty.Register("Value",
typeof(T), typeof(AbstractBaseUpDown<T>),
new PropertyMetadata(_MinValue, new PropertyChangedCallback(OnValueChanged),
Expand All @@ -77,7 +77,7 @@ public abstract partial class AbstractBaseUpDown<T> : InputBaseUpDown, ICommandS
/// <summary>
/// Dependency property backing store for Minimum Value property.
/// </summary>
protected static readonly DependencyProperty MinValueProperty =
public static readonly DependencyProperty MinValueProperty =
DependencyProperty.Register("MinValue",
typeof(T), typeof(AbstractBaseUpDown<T>),
new PropertyMetadata(_MinValue, new PropertyChangedCallback(OnMinValueChanged),
Expand All @@ -86,7 +86,7 @@ public abstract partial class AbstractBaseUpDown<T> : InputBaseUpDown, ICommandS
/// <summary>
/// Dependency property backing store for Maximum Value property.
/// </summary>
protected static readonly DependencyProperty MaxValueProperty =
public static readonly DependencyProperty MaxValueProperty =
DependencyProperty.Register("MaxValue",
typeof(T), typeof(AbstractBaseUpDown<T>),
new PropertyMetadata(_MaxValue, new PropertyChangedCallback(OnMaxValueChanged),
Expand Down Expand Up @@ -124,7 +124,7 @@ public abstract partial class AbstractBaseUpDown<T> : InputBaseUpDown, ICommandS
/// that should be displayed in the control without having to scroll inside
/// the textbox portion.
/// </summary>
protected static readonly DependencyProperty DisplayLengthProperty =
public static readonly DependencyProperty DisplayLengthProperty =
DependencyProperty.Register("DisplayLength", typeof(byte),
typeof(AbstractBaseUpDown<T>), new PropertyMetadata((byte)3));

Expand All @@ -134,23 +134,23 @@ public abstract partial class AbstractBaseUpDown<T> : InputBaseUpDown, ICommandS
/// if user types longer string), or not (control will resize in dependence
/// of string length and available space).
/// </summary>
protected static readonly DependencyProperty IsDisplayLengthFixedProperty =
public static readonly DependencyProperty IsDisplayLengthFixedProperty =
DependencyProperty.Register("IsDisplayLengthFixed",
typeof(bool), typeof(AbstractBaseUpDown<T>), new PropertyMetadata(true, OnIsDisplayLengthFixedChanged));

/// <summary>
/// Backing store for dependency property to decide whether all text in textbox
/// should be selected upon focus or not.
/// </summary>
protected static readonly DependencyProperty SelectAllTextOnFocusProperty =
public static readonly DependencyProperty SelectAllTextOnFocusProperty =
DependencyProperty.Register("SelectAllTextOnFocus",
typeof(bool), typeof(AbstractBaseUpDown<T>), new PropertyMetadata(true));

/// <summary>
/// Backing store for dependency property for .Net FormatString that is
/// applied to the textbox text portion of the up down control.
/// </summary>
protected static readonly DependencyProperty FormatStringProperty =
public static readonly DependencyProperty FormatStringProperty =
DependencyProperty.Register("FormatString", typeof(string),
typeof(AbstractBaseUpDown<T>), new PropertyMetadata("G", OnIsFormatStringChanged));

Expand All @@ -176,15 +176,15 @@ public abstract partial class AbstractBaseUpDown<T> : InputBaseUpDown, ICommandS
DependencyProperty.Register("CanMouseDrag", typeof(CanIncDecMouseDrag),
typeof(AbstractBaseUpDown<T>), new PropertyMetadata(CanIncDecMouseDrag.VerticalHorizontal));

public static readonly DependencyProperty MouseWheelEnabledProperty =
DependencyProperty.Register("MouseWheelEnabled", typeof(bool),
typeof(AbstractBaseUpDown<T>),
new PropertyMetadata(true));
public static readonly DependencyProperty MouseWheelEnabledProperty =
DependencyProperty.Register("MouseWheelEnabled", typeof(bool),
typeof(AbstractBaseUpDown<T>),
new PropertyMetadata(true));

/// <summary>
/// Backing store of <see cref="IsLargeStepEnabled"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsLargeStepEnabledProperty =
/// <summary>
/// Backing store of <see cref="IsLargeStepEnabled"/> dependency property.
/// </summary>
public static readonly DependencyProperty IsLargeStepEnabledProperty =
DependencyProperty.Register("IsLargeStepEnabled", typeof(bool),
typeof(AbstractBaseUpDown<T>), new PropertyMetadata(true));

Expand Down Expand Up @@ -325,7 +325,7 @@ public IInputElement CommandTarget
/// (supporting <see cref="RoutedCommand"/> and <see cref="ICommand"/> bindings)
/// </summary>
/// <param name="cmd"></param>
private void CommandExecute(ICommand cmd)
protected void CommandExecute(ICommand cmd)
{
if (cmd is RoutedCommand command)
command.Execute(CommandParameter, CommandTarget);
Expand All @@ -340,7 +340,7 @@ private void CommandExecute(ICommand cmd)
/// </summary>
/// <param name="oldCommand"></param>
/// <param name="newCommand"></param>
private void HookUpCommand(ICommand oldCommand, ICommand newCommand)
protected void HookUpCommand(ICommand oldCommand, ICommand newCommand)
{
if (oldCommand != null)
{
Expand All @@ -359,7 +359,7 @@ private void HookUpCommand(ICommand oldCommand, ICommand newCommand)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void CanExecuteChanged(object sender, EventArgs e)
protected void CanExecuteChanged(object sender, EventArgs e)
{
if (this.Command is RoutedCommand command)
{
Expand Down Expand Up @@ -442,23 +442,23 @@ public byte DisplayLength
set { SetValue(DisplayLengthProperty, value); }
}

/// <summary>
/// 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
/// <summary>
/// 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.
/// </summary>
public virtual double MinWidth
/// </summary>
public virtual double MinWidth
{
get { return (double)GetValue(MinWidthProperty); }
set { SetValue(MinWidthProperty, value); }
}

/// <summary>
/// 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.
/// </summary>
public bool IsDisplayLengthFixed
/// <summary>
/// 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.
/// </summary>
public bool IsDisplayLengthFixed
{
get { return (bool)GetValue(IsDisplayLengthFixedProperty); }
set { SetValue(IsDisplayLengthFixedProperty, value); }
Expand Down Expand Up @@ -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); }
}

/// <summary>
/// Gets/sets wether enable large step Increment/Decrement
/// </summary>
public bool IsLargeStepEnabled
/// <summary>
/// Gets/sets wether enable large step Increment/Decrement
/// </summary>
public bool IsLargeStepEnabled
{
get { return (bool)GetValue(IsLargeStepEnabledProperty); }
set { SetValue(IsLargeStepEnabledProperty, value); }
Expand Down Expand Up @@ -600,7 +600,7 @@ protected set
/// <summary>
/// Determines whether last text input was from a user (key was down) or not.
/// </summary>
protected bool UserInput { get; set; }
public bool UserInput { get; protected set; }
#endregion properties

#region methods
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -716,14 +716,14 @@ protected override void OnMouseWheel(MouseWheelEventArgs e)
}
}

#region IsMouseDragEnabled
/// <summary>
/// Is invoked when <see cref="IsMouseDragEnabled"/> dependency property value
/// has been changed to update all states accordingly.
/// </summary>
/// <param name="d"></param>
/// <param name="e"></param>
private static void OnIsMouseDragEnabledChanged(DependencyObject d,
#region IsMouseDragEnabled
/// <summary>
/// Is invoked when <see cref="IsMouseDragEnabled"/> dependency property value
/// has been changed to update all states accordingly.
/// </summary>
/// <param name="d"></param>
/// <param name="e"></param>
private static void OnIsMouseDragEnabledChanged(DependencyObject d,
DependencyPropertyChangedEventArgs e)
{
(d as AbstractBaseUpDown<T>).OnIsMouseDragEnabledChanged(e);
Expand Down Expand Up @@ -1148,67 +1148,67 @@ private bool IsModifierKeyDown()
}


/// <summary>
/// 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.
/// </summary>
/// <param name="number">.Net type specific value to be formated as string</param>
/// <returns>The string that was formatted with the FormatString
/// dependency property</returns>
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);
}

/// <summary>
/// Checks if the current string entered in the textbox is:
/// 1) A valid number (syntax)
/// 2) within bounds (Min &lt;= number &lt;= Max )
///
/// 3) adjusts the string if it appears to be invalid and
///
/// 4) <paramref name="formatNumber"/> true:
/// Applies the FormatString property to format the text in a certain way
/// </summary>
/// <param name="text"></param>
/// <param name="formatNumber"></param>
/// <returns>the value of the string with special format</returns>
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);

/// <summary>
/// <summary>
/// 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.
/// </summary>
/// <param name="number">.Net type specific value to be formated as string</param>
/// <returns>The string that was formatted with the FormatString
/// dependency property</returns>
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);
}

/// <summary>
/// Checks if the current string entered in the textbox is:
/// 1) A valid number (syntax)
/// 2) within bounds (Min &lt;= number &lt;= Max )
///
/// 3) adjusts the string if it appears to be invalid and
///
/// 4) <paramref name="formatNumber"/> true:
/// Applies the FormatString property to format the text in a certain way
/// </summary>
/// <param name="text"></param>
/// <param name="formatNumber"></param>
/// <returns>the value of the string with special format</returns>
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);

/// <summary>
/// Verify the text is valid or not while use is typing
/// </summary>
/// <param name="text"></param>
Expand Down
8 changes: 4 additions & 4 deletions source/NumericUpDownLib/Base/InputBaseUpDown.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@ public abstract class InputBaseUpDown : Control
/// identify that the inputing data is valid or not.,
/// </summary>
/// <value></value>
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); }
}

/// <summary>
/// identify that the editing Visibility
/// </summary>
/// <value></value>
protected Visibility EditingVisibility
public Visibility EditingVisibility
{
get { return (Visibility)GetValue(EditingVisibilityProperty); }
set { SetValue(EditingVisibilityProperty, value); }
protected set { SetValue(EditingVisibilityProperty, value); }
}

/// <summary>
Expand Down