Merge pull request #175 from heartacker/acker/number_bug_fix_new_freature_3_21
1. fix OnFormatChange
This commit is contained in:
@@ -6,10 +6,10 @@
|
|||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:u="https://irihi.tech/ursa"
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
xmlns:vm="using:Ursa.Demo.ViewModels"
|
xmlns:vm="using:Ursa.Demo.ViewModels"
|
||||||
x:DataType="vm:NumericUpDownDemoViewModel"
|
|
||||||
x:CompileBindings="True"
|
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
|
x:CompileBindings="True"
|
||||||
|
x:DataType="vm:NumericUpDownDemoViewModel"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
|
|
||||||
<UserControl.Styles>
|
<UserControl.Styles>
|
||||||
@@ -20,33 +20,35 @@
|
|||||||
</Style>
|
</Style>
|
||||||
</UserControl.Styles>
|
</UserControl.Styles>
|
||||||
|
|
||||||
<Grid ColumnDefinitions="*,*">
|
<Grid ColumnDefinitions="*,*" RowDefinitions="100,*">
|
||||||
<Grid
|
<StackPanel Grid.ColumnSpan="2">
|
||||||
Grid.Column="0"
|
<u:Divider Content="Change Right ->" />
|
||||||
HorizontalAlignment="Left"
|
<u:NumericUIntUpDown
|
||||||
RowDefinitions="200,*">
|
Name="numd"
|
||||||
<StackPanel>
|
Width="{Binding Width}"
|
||||||
<u:Divider Content="Change Right ->" />
|
HorizontalAlignment="{Binding HorizontalAlignment}"
|
||||||
<u:NumericUIntUpDown
|
HorizontalContentAlignment="{Binding HorizontalContentAlignment}"
|
||||||
Name="numd"
|
AllowDrag="{Binding AllowDrag}"
|
||||||
HorizontalContentAlignment="{Binding HorizontalContentAlignment}"
|
AllowSpin="{Binding AllowSpin}"
|
||||||
AllowDrag="{Binding AllowDrag}"
|
FontFamily="{Binding FontFamily, Mode=OneWay}"
|
||||||
AllowSpin="{Binding AllowSpin}"
|
FormatString="{Binding FormatString}"
|
||||||
FontFamily="{Binding FontFamily, Mode=OneWay}"
|
InnerLeftContent="{Binding InnerLeftContent}"
|
||||||
FormatString="{Binding FormatString}"
|
IsEnabled="{Binding IsEnable}"
|
||||||
InnerLeftContent="{Binding InnerLeftContent}"
|
IsReadOnly="{Binding IsReadOnly}"
|
||||||
IsEnabled="{Binding IsEnable}"
|
Maximum="{Binding Maximum}"
|
||||||
IsReadOnly="{Binding IsReadOnly}"
|
Minimum="{Binding Minimum}"
|
||||||
Maximum="{Binding Maximum}"
|
ParsingNumberStyle="{Binding ParsingNumberStyle}"
|
||||||
Minimum="{Binding Minimum}"
|
ShowButtonSpinner="{Binding ShowButtonSpinner}"
|
||||||
ParsingNumberStyle="{Binding ParsingNumberStyle}"
|
Step="{Binding Step}"
|
||||||
ShowButtonSpinner="{Binding ShowButtonSpinner}"
|
Watermark="{Binding Watermark}"
|
||||||
Step="{Binding Step}"
|
Value="{Binding Value}" />
|
||||||
Watermark="{Binding Watermark}"
|
<u:Divider Content="Demo" />
|
||||||
Value="{Binding Value}" />
|
</StackPanel>
|
||||||
<u:Divider Content="Demo" />
|
|
||||||
</StackPanel>
|
|
||||||
|
|
||||||
|
<Grid
|
||||||
|
Grid.Row="1"
|
||||||
|
Grid.Column="0"
|
||||||
|
HorizontalAlignment="Left">
|
||||||
<StackPanel Grid.Row="1">
|
<StackPanel Grid.Row="1">
|
||||||
<u:Divider Content="{Binding #input.Value, StringFormat='Int = {0}'}" />
|
<u:Divider Content="{Binding #input.Value, StringFormat='Int = {0}'}" />
|
||||||
<u:NumericIntUpDown
|
<u:NumericIntUpDown
|
||||||
@@ -119,43 +121,50 @@
|
|||||||
Value="2" />
|
Value="2" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
<StackPanel Grid.Column="1" HorizontalAlignment="Left">
|
|
||||||
|
|
||||||
<Label Content="FontFamily" />
|
<StackPanel
|
||||||
<TextBox Text="{Binding FontFamily}" />
|
Grid.Row="1"
|
||||||
|
Grid.Column="1"
|
||||||
|
HorizontalAlignment="Left"
|
||||||
|
Orientation="Vertical">
|
||||||
|
|
||||||
<Label Content="AllowDrag" />
|
<CheckBox Content="AutoWidth" IsChecked="{Binding AutoWidth}" />
|
||||||
<CheckBox IsChecked="{Binding AllowDrag}" />
|
<u:NumericDoubleUpDown
|
||||||
|
AllowDrag="True"
|
||||||
|
InnerLeftContent="Width"
|
||||||
|
IsEnabled="{Binding !AutoWidth}"
|
||||||
|
Value="{Binding Width}" />
|
||||||
|
|
||||||
<Label Content="IsReadOnly" />
|
<TextBox InnerLeftContent="FontFamily" Text="{Binding FontFamily}" />
|
||||||
<CheckBox IsChecked="{Binding IsReadOnly}" />
|
|
||||||
|
|
||||||
|
<CheckBox Content="AllowDrag" IsChecked="{Binding AllowDrag}" />
|
||||||
|
|
||||||
|
<CheckBox Content="IsReadOnly" IsChecked="{Binding IsReadOnly}" />
|
||||||
|
|
||||||
|
<Label Content="HorizontalAlignment" />
|
||||||
|
<ComboBox ItemsSource="{Binding Array_HorizontalAlignment}" SelectedItem="{Binding HorizontalAlignment}" />
|
||||||
<Label Content="HorizontalContentAlignment" />
|
<Label Content="HorizontalContentAlignment" />
|
||||||
<ComboBox ItemsSource="{Binding Array_HorizontalContentAlignment}" SelectedItem="{Binding HorizontalContentAlignment}" />
|
<ComboBox ItemsSource="{Binding Array_HorizontalContentAlignment}" SelectedItem="{Binding HorizontalContentAlignment}" />
|
||||||
|
|
||||||
<Label Content="InnerLeftContent" />
|
<TextBox
|
||||||
<TextBox Text="{Binding InnerLeftContent}" />
|
InnerLeftContent="InnerLeftContent"
|
||||||
|
InnerRightContent="obj"
|
||||||
|
Text="{Binding InnerLeftContent}" />
|
||||||
|
|
||||||
|
<TextBox InnerLeftContent="Watermark" Text="{Binding Watermark}" />
|
||||||
|
|
||||||
<Label Content="Watermark" />
|
|
||||||
<TextBox Text="{Binding Watermark}" />
|
|
||||||
|
|
||||||
|
|
||||||
<Label Content="FormatString" />
|
|
||||||
<TextBox
|
<TextBox
|
||||||
MinWidth="100"
|
MinWidth="100"
|
||||||
|
InnerLeftContent="FormatString"
|
||||||
MaxLength="100"
|
MaxLength="100"
|
||||||
Text="{Binding FormatString}" />
|
Text="{Binding FormatString}" />
|
||||||
|
|
||||||
<Label Content="ParsingNumberStyle" />
|
<Label Content="ParsingNumberStyle" />
|
||||||
<ComboBox ItemsSource="{Binding Array_ParsingNumberStyle}" SelectedItem="{Binding ParsingNumberStyle}" />
|
<ComboBox ItemsSource="{Binding Array_ParsingNumberStyle}" SelectedItem="{Binding ParsingNumberStyle}" />
|
||||||
|
|
||||||
|
<CheckBox Content="AllowSpin" IsChecked="{Binding AllowSpin}" />
|
||||||
|
|
||||||
<Label Content="AllowSpin" />
|
<CheckBox Content="ShowButtonSpinner" IsChecked="{Binding ShowButtonSpinner}" />
|
||||||
<CheckBox IsChecked="{Binding AllowSpin}" />
|
|
||||||
|
|
||||||
<Label Content="ShowButtonSpinner" />
|
|
||||||
<CheckBox IsChecked="{Binding ShowButtonSpinner}" />
|
|
||||||
|
|
||||||
<u:NumericUIntUpDown
|
<u:NumericUIntUpDown
|
||||||
Name="nudV"
|
Name="nudV"
|
||||||
@@ -169,12 +178,14 @@
|
|||||||
|
|
||||||
<u:NumericUIntUpDown InnerLeftContent="Min" Value="{Binding Minimum}" />
|
<u:NumericUIntUpDown InnerLeftContent="Min" Value="{Binding Minimum}" />
|
||||||
|
|
||||||
<Label Content="Step" />
|
<Label Content="{Binding Step, StringFormat='Step {0}'}" />
|
||||||
<Slider Minimum="1" Value="{Binding Step}" />
|
<Slider
|
||||||
|
Minimum="1"
|
||||||
|
ToolTip.Tip="{Binding Step}"
|
||||||
|
Value="{Binding Step}" />
|
||||||
|
|
||||||
<Label Content="IsEnable" />
|
<CheckBox Content="IsEnable" IsChecked="{Binding IsEnable}" />
|
||||||
<CheckBox IsChecked="{Binding IsEnable}" />
|
|
||||||
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
@@ -11,11 +11,18 @@ namespace Ursa.Demo.ViewModels;
|
|||||||
public partial class NumericUpDownDemoViewModel : ObservableObject
|
public partial class NumericUpDownDemoViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
|
private double _oldWidth = 300;
|
||||||
|
[ObservableProperty] private bool _AutoWidth = true;
|
||||||
|
[ObservableProperty] private double _Width = Double.NaN;
|
||||||
[ObservableProperty] private uint _Value;
|
[ObservableProperty] private uint _Value;
|
||||||
[ObservableProperty] private string _FontFamily = "Consolas";
|
[ObservableProperty] private string _FontFamily = "Consolas";
|
||||||
[ObservableProperty] private bool _AllowDrag = false;
|
[ObservableProperty] private bool _AllowDrag = false;
|
||||||
[ObservableProperty] private bool _IsReadOnly = false;
|
[ObservableProperty] private bool _IsReadOnly = false;
|
||||||
|
|
||||||
|
[ObservableProperty] private Array _Array_HorizontalAlignment;
|
||||||
|
[ObservableProperty] private HorizontalAlignment _HorizontalAlignment = HorizontalAlignment.Center;
|
||||||
|
|
||||||
[ObservableProperty] private Array _Array_HorizontalContentAlignment;
|
[ObservableProperty] private Array _Array_HorizontalContentAlignment;
|
||||||
[ObservableProperty] private HorizontalAlignment _HorizontalContentAlignment = HorizontalAlignment.Center;
|
[ObservableProperty] private HorizontalAlignment _HorizontalContentAlignment = HorizontalAlignment.Center;
|
||||||
[ObservableProperty] private object? _InnerLeftContent = "obj:0x";
|
[ObservableProperty] private object? _InnerLeftContent = "obj:0x";
|
||||||
@@ -36,12 +43,26 @@ public partial class NumericUpDownDemoViewModel : ObservableObject
|
|||||||
public NumericUpDownDemoViewModel()
|
public NumericUpDownDemoViewModel()
|
||||||
{
|
{
|
||||||
Array_HorizontalContentAlignment = Enum.GetValues(typeof(HorizontalAlignment));
|
Array_HorizontalContentAlignment = Enum.GetValues(typeof(HorizontalAlignment));
|
||||||
|
Array_HorizontalAlignment = Enum.GetValues(typeof(HorizontalAlignment));
|
||||||
Array_ParsingNumberStyle = Enum.GetValues(typeof(NumberStyles));
|
Array_ParsingNumberStyle = Enum.GetValues(typeof(NumberStyles));
|
||||||
NumericUIntUpDown numericUIntUpDown;
|
NumericUIntUpDown numericUIntUpDown;
|
||||||
TextBox textBox;
|
TextBox textBox;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
partial void OnAutoWidthChanged(bool value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
_oldWidth = Width;
|
||||||
|
Width = double.NaN;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Width = _oldWidth;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
partial void OnValueChanging(uint oldValue, uint newValue)
|
partial void OnValueChanging(uint oldValue, uint newValue)
|
||||||
{
|
{
|
||||||
Console.WriteLine(oldValue);
|
Console.WriteLine(oldValue);
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
|||||||
{
|
{
|
||||||
if (IsInitialized)
|
if (IsInitialized)
|
||||||
{
|
{
|
||||||
SyncTextAndValue(false, null);
|
SyncTextAndValue(false, null, true);//sync text update while OnFormatChange
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,7 +343,11 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
|||||||
|
|
||||||
if ((numberStyles & NumberStyles.AllowHexSpecifier) != 0)
|
if ((numberStyles & NumberStyles.AllowHexSpecifier) != 0)
|
||||||
{
|
{
|
||||||
if (text.StartsWith("0X") || text.StartsWith("0x")) // support 0x hex while user input
|
if (text.StartsWith("0x") || text.StartsWith("0X")) // support 0x hex while user input
|
||||||
|
{
|
||||||
|
text = text.Substring(2);
|
||||||
|
}
|
||||||
|
else if (text.StartsWith("h'") || text.StartsWith("H'")) // support verilog hex while user input
|
||||||
{
|
{
|
||||||
text = text.Substring(2);
|
text = text.Substring(2);
|
||||||
}
|
}
|
||||||
@@ -351,12 +355,25 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
|||||||
{
|
{
|
||||||
text = text.Substring(1);
|
text = text.Substring(1);
|
||||||
}
|
}
|
||||||
else if (text.StartsWith("h'") || text.StartsWith("H'")) // support hex while user input
|
}
|
||||||
|
#if NET8_0_OR_GREATER
|
||||||
|
else if ((numberStyles & NumberStyles.AllowBinarySpecifier) != 0)
|
||||||
|
{
|
||||||
|
if (text.StartsWith("0b") || text.StartsWith("0B")) // support 0b bin while user input
|
||||||
{
|
{
|
||||||
text = text.Substring(2);
|
text = text.Substring(2);
|
||||||
}
|
}
|
||||||
|
else if (text.StartsWith("b'") || text.StartsWith("B'")) // support verilog bin while user input
|
||||||
|
{
|
||||||
|
text = text.Substring(2);
|
||||||
|
}
|
||||||
|
else if (text.StartsWith("b") || text.StartsWith("B")) // support bin while user input
|
||||||
|
{
|
||||||
|
text = text.Substring(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<Import Project="../Package.props"/>
|
<Import Project="../Package.props"/>
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>netstandard2.0</TargetFramework>
|
<TargetFrameworks>netstandard2.0;net8</TargetFrameworks>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<LangVersion>latest</LangVersion>
|
<LangVersion>latest</LangVersion>
|
||||||
|
|||||||
Reference in New Issue
Block a user