Skip to content

Commit

Permalink
Merge pull request #54 from heartacker/fixLastEditingNumericValueError
Browse files Browse the repository at this point in the history
LastEditingNumericValue should be as same as Value when ValueChanged
  • Loading branch information
Dirkster99 authored Dec 20, 2022
2 parents 68d5b83 + a515a38 commit da473e2
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 57 deletions.
22 changes: 10 additions & 12 deletions source/NumericUpDownLib/Base/AbstractBaseUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -435,19 +435,19 @@ public byte DisplayLength
{
get { return (byte)GetValue(DisplayLengthProperty); }
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
/// UpDown buttons are auto sized.
/// </summary>
public virtual double MinWidth
{
get { return (double)GetValue(MinWidthProperty); }
set { SetValue(MinWidthProperty, value); }
}

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
Expand Down Expand Up @@ -703,7 +703,7 @@ protected override void OnMouseWheel(MouseWheelEventArgs e)
}
}
}

#region IsMouseDragEnabled
/// <summary>
/// Is invoked when <see cref="IsMouseDragEnabled"/> dependency property value
Expand Down Expand Up @@ -962,7 +962,6 @@ private void _PART_TextBox_LostFocus(object sender, RoutedEventArgs e)
if (IsUpdateValueWhenLostFocus && IsValueValid)
{
Value = FormatText(_PART_TextBox.Text, true);
LastEditingNumericValue = Value;
}
}
}
Expand All @@ -988,7 +987,6 @@ protected void _PART_TextBox_TextChanged(object sender,
if (UserInput == true)
{
T temp = LastEditingNumericValue;
WaterMarkVisibility = string.IsNullOrEmpty(_PART_TextBox.Text) ? Visibility.Visible : Visibility.Collapsed;
IsValueValid = VerifyText(_PART_TextBox.Text, ref temp);
if (!LastEditingNumericValue.Equals(temp))
{
Expand Down Expand Up @@ -1112,7 +1110,6 @@ private void textBox_PreviewKeyDown(object sender, KeyEventArgs e)
}
T OldValue = Value;
Value = FormatText(_PART_TextBox.Text, true);
LastEditingNumericValue = Value;

// force to raise value changed event to tigger re write /re-set for application
if (OldValue.Equals(Value) && isCtrlDown)
Expand Down Expand Up @@ -1224,6 +1221,7 @@ protected virtual void OnValueChanged(RoutedPropertyChangedEventArgs<T> args)
if (_PART_TextBox != null)
{
_PART_TextBox.Text = FormatNumber(Value);
LastEditingNumericValue = Value;
}
CommandExecute(Command);
this.RaiseEvent(args);
Expand Down
10 changes: 2 additions & 8 deletions source/NumericUpDownLib/Base/InputBaseUpDown.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,13 @@
HorizontalContentAlignment="Right"
VerticalContentAlignment="{TemplateBinding VerticalAlignment}"
AcceptsReturn="False"
Background="{TemplateBinding Background}"
Background="#00000000"
Foreground="#00000000"
IsEnabled="False"
SpellCheck.IsEnabled="False"
Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DisplayLength, Converter={StaticResource ByteToPlaceHolderStringConverter}}"
TextAlignment="Right" />
<!-- Visibility="Hidden" /> -->
<TextBox
MaxWidth="{Binding Path=Width, ElementName=PART_Measuring_Element, Mode=OneWay}"
Background="#00ffffff"
Foreground="#80808080"
Text="{Binding Path=WaterMark, RelativeSource={RelativeSource AncestorType={x:Type local:InputBaseUpDown}}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
Visibility="{TemplateBinding WaterMarkVisibility}" />

<TextBox
x:Name="PART_TextBox"
Expand All @@ -60,7 +54,7 @@
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="Center"
AcceptsReturn="False"
Background="#00FFFFFF"
Background="{TemplateBinding Background}"
BorderThickness="0"
Foreground="{TemplateBinding Foreground}"
IsReadOnly="{TemplateBinding IsReadOnly}"
Expand Down
32 changes: 0 additions & 32 deletions source/NumericUpDownLib/Base/InputBaseUpDown.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ public abstract class InputBaseUpDown : Control
DependencyProperty.Register("NumberStyle", typeof(NumberStyles),
typeof(InputBaseUpDown), new PropertyMetadata(NumberStyles.Any));

/// <summary>
/// Determines the WaterMark in the textbox.
/// </summary>
public static readonly DependencyProperty WaterMarkProperty =
DependencyProperty.Register("WaterMark", typeof(string),
typeof(InputBaseUpDown), new PropertyMetadata(string.Empty));

/// <summary>
/// Backing store of <see cref="WaterMarkVisibility"/> dependency property.
/// </summary>
public static readonly DependencyProperty WaterMarkVisibilityProperty =
DependencyProperty.Register("WaterMarkVisibility", typeof(Visibility), typeof(InputBaseUpDown), new PropertyMetadata(Visibility.Collapsed));

/// <summary>
/// Backing store of <see cref="EnableValidatingIndicator"/> dependency property.
/// </summary>
Expand Down Expand Up @@ -144,25 +131,6 @@ public NumberStyles NumberStyle
set { SetValue(NumberStyleProperty, value); }
}

/// <summary>
/// Gets/sets the watermark style of a number entered and displayed in the textbox.
/// </summary>
public string WaterMark
{
get { return (string)GetValue(WaterMarkProperty); }
set { SetValue(WaterMarkProperty, value); }
}

/// <summary>
/// identify that the WaterMark Visibility
/// </summary>
/// <value></value>
protected Visibility WaterMarkVisibility
{
get { return (Visibility)GetValue(WaterMarkVisibilityProperty); }
set { SetValue(WaterMarkVisibilityProperty, value); }
}

#endregion properties

#region methods
Expand Down
10 changes: 5 additions & 5 deletions source/NumericUpDownLib/NumericUpDownLib.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFrameworks>net4;netcoreapp3.0</TargetFrameworks>
<UseWPF>true</UseWPF>

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>3.3.0.0</Version>
<AssemblyVersion>3.3.0.0</AssemblyVersion>
<FileVersion>3.3.0.0</FileVersion>
<Version>3.3.1.0</Version>
<AssemblyVersion>3.3.1.0</AssemblyVersion>
<FileVersion>3.3.1.0</FileVersion>
<Company>Open Source</Company>
<Product>NumericUpDownLib</Product>
<Copyright>2013-2021</Copyright>
<Copyright>2013-2022</Copyright>
<Description>Provides a numeric up down WPF control that can be used to edit (integer, byte, decimal, double, float, short and many more) values with a textbox and/or up/down arrow (repeat) buttons. Editing can be based on input via mouse wheel, mouse drag, cursor keys, or text editing.</Description>
<PackageProjectUrl>https://github.com/Dirkster99/NumericUpDownLib</PackageProjectUrl>
<RepositoryUrl>https://github.com/Dirkster99/NumericUpDownLib</RepositoryUrl>
Expand Down

0 comments on commit da473e2

Please sign in to comment.