Skip to content

Commit caf1d7d

Browse files
committed
support disable editingTip Fixes #37
1 parent cee8c39 commit caf1d7d

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

source/NumericUpDownLib/Base/AbstractBaseUpDown.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,10 @@ public bool IsUpdateValueWhenLostFocus
423423
/// <summary>
424424
/// Gets/sets determines the input text is valid or not.
425425
/// </summary>
426-
protected bool IsDataValid
426+
public bool IsValueValid
427427
{
428428
get { return _IsDataValid; }
429-
set
429+
protected set
430430
{
431431
if (_IsDataValid != value)
432432
{
@@ -437,7 +437,7 @@ protected bool IsDataValid
437437
new System.Windows.Media.SolidColorBrush(System.Windows.Media.Colors.Red);
438438

439439
// FIX THE behavior when user input unsupported char like ghijk
440-
if (!_IsDataValid)
440+
if (IsEnableValidatingIndicator && !_IsDataValid)
441441
{
442442
EditingVisibility = Visibility.Visible;
443443
}
@@ -456,7 +456,8 @@ protected T LastEditingNumericValue
456456
set
457457
{
458458
lastEditingNumericValue = value;
459-
EditingVisibility = lastEditingNumericValue.Equals(Value) ? Visibility.Hidden : Visibility.Visible;
459+
if(IsEnableValidatingIndicator)
460+
EditingVisibility = lastEditingNumericValue.Equals(Value) ? Visibility.Hidden : Visibility.Visible;
460461
}
461462
}
462463

@@ -832,7 +833,7 @@ private void _PART_TextBox_LostFocus(object sender, RoutedEventArgs e)
832833
FormatText(_PART_TextBox.Text);
833834

834835
// trigger the change event if IsUpdateValueWhenLostFocus=true and value is valid
835-
if (IsUpdateValueWhenLostFocus && IsDataValid)
836+
if (IsUpdateValueWhenLostFocus && IsValueValid)
836837
{
837838
Value = FormatText(_PART_TextBox.Text, true);
838839
LastEditingNumericValue = Value;
@@ -861,7 +862,7 @@ protected void _PART_TextBox_TextChanged(object sender,
861862
if (UserInput == true)
862863
{
863864
T temp = LastEditingNumericValue;
864-
IsDataValid = VerifyText(_PART_TextBox.Text, ref temp);
865+
IsValueValid = VerifyText(_PART_TextBox.Text, ref temp);
865866
if (!LastEditingNumericValue.Equals(temp))
866867
{
867868
LastEditingNumericValue = temp;
@@ -975,7 +976,7 @@ private void textBox_PreviewKeyDown(object sender, KeyEventArgs e)
975976
{
976977
if (_PART_TextBox != null)
977978
{
978-
if (!IsDataValid)
979+
if (!IsValueValid)
979980
{
980981
e.Handled = true;
981982
return;

source/NumericUpDownLib/Base/InputBaseUpDown.xaml.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ public abstract class InputBaseUpDown : Control
2727
DependencyProperty.Register("NumberStyle", typeof(NumberStyles),
2828
typeof(InputBaseUpDown), new PropertyMetadata(NumberStyles.Any));
2929

30+
/// <summary>
31+
/// Backing store of <see cref="IsEnableValidatingIndicator"/> dependency property.
32+
/// </summary>
33+
public static readonly DependencyProperty IsEnableValidatingIndicatorProperty =
34+
DependencyProperty.Register("IsEnableValidatingIndicator", typeof(bool), typeof(InputBaseUpDown), new PropertyMetadata(true));
35+
3036
/// <summary>
3137
/// Backing store of <see cref="EditingVisibility"/> dependency property.
3238
/// </summary>
3339
public static readonly DependencyProperty EditingVisibilityProperty =
34-
DependencyProperty.Register("EditingVisibility", typeof(Visibility),
35-
typeof(InputBaseUpDown), new PropertyMetadata(Visibility.Hidden));
40+
DependencyProperty.Register("EditingVisibility", typeof(Visibility), typeof(InputBaseUpDown), new PropertyMetadata(Visibility.Hidden));
3641

3742
/// <summary>
3843
/// Backing store of <see cref="EditingColorBrush"/> dependency property.
@@ -43,7 +48,7 @@ public abstract class InputBaseUpDown : Control
4348

4449

4550
/// <summary>
46-
/// identify that the inputing data is value,
51+
/// identify that the inputing data is valid or not.,
4752
/// </summary>
4853
/// <value></value>
4954
protected System.Windows.Media.SolidColorBrush EditingColorBrush
@@ -52,12 +57,25 @@ protected System.Windows.Media.SolidColorBrush EditingColorBrush
5257
set { SetValue(EditingColorBrushProperty, value); }
5358
}
5459

60+
/// <summary>
61+
/// identify that the editing Visibility
62+
/// </summary>
63+
/// <value></value>
5564
protected Visibility EditingVisibility
5665
{
5766
get { return (Visibility)GetValue(EditingVisibilityProperty); }
5867
set { SetValue(EditingVisibilityProperty, value); }
5968
}
6069

70+
/// <summary>
71+
/// identify that the is enable the red/green tip while editing
72+
/// </summary>
73+
/// <value></value>
74+
protected bool IsEnableValidatingIndicator
75+
{
76+
get { return (bool)GetValue(IsEnableValidatingIndicatorProperty); }
77+
set { SetValue(IsEnableValidatingIndicatorProperty, value); }
78+
}
6179

6280
private static RoutedCommand _IncreaseCommand;
6381
private static RoutedCommand _DecreaseCommand;

0 commit comments

Comments
 (0)