Skip to content
Merged
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
32 changes: 30 additions & 2 deletions source/NumericUpDownLib/Base/AbstractBaseUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,13 @@ public abstract partial class AbstractBaseUpDown<T> : InputBaseUpDown
DependencyProperty.Register("IsLargeStepEnabled", typeof(bool),
typeof(AbstractBaseUpDown<T>), new PropertyMetadata(true));

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

/// <summary>
/// Holds the REQUIRED textbox instance part for this control.
/// </summary>
Expand Down Expand Up @@ -402,6 +409,15 @@ public bool IsLargeStepEnabled
set { SetValue(IsLargeStepEnabledProperty, value); }
}

/// <summary>
/// Gets/sets wether enable updata Value when Lost Focus
/// </summary>
public bool IsUpdateValueWhenLostFocus
{
get { return (bool)GetValue(IsUpdateValueWhenLostFocusProperty); }
set { SetValue(IsUpdateValueWhenLostFocusProperty, value); }
}

private bool _IsDataValid;

/// <summary>
Expand Down Expand Up @@ -808,8 +824,20 @@ private void _PART_TextBox_LostFocus(object sender, RoutedEventArgs e)
_objMouseIncr = null;
(sender as TextBox).Cursor = Cursors.ScrollAll;
}
if (_PART_TextBox != null && Value.Equals(LastEditingNumericValue))
FormatText(_PART_TextBox.Text);

if (_PART_TextBox != null)
{
// format the value string if value is no changed
if (Value.Equals(LastEditingNumericValue))
FormatText(_PART_TextBox.Text);

// trigger the change event if IsUpdateValueWhenLostFocus=true and value is valid
if (IsUpdateValueWhenLostFocus && IsDataValid)
{
Value = FormatText(_PART_TextBox.Text, true);
LastEditingNumericValue = Value;
}
}
}
#endregion textbox mouse and focus handlers

Expand Down