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:u="https://irihi.tech/ursa"
|
||||
xmlns:vm="using:Ursa.Demo.ViewModels"
|
||||
x:DataType="vm:NumericUpDownDemoViewModel"
|
||||
x:CompileBindings="True"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="vm:NumericUpDownDemoViewModel"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<UserControl.Styles>
|
||||
@@ -20,33 +20,35 @@
|
||||
</Style>
|
||||
</UserControl.Styles>
|
||||
|
||||
<Grid ColumnDefinitions="*,*">
|
||||
<Grid
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Left"
|
||||
RowDefinitions="200,*">
|
||||
<StackPanel>
|
||||
<u:Divider Content="Change Right ->" />
|
||||
<u:NumericUIntUpDown
|
||||
Name="numd"
|
||||
HorizontalContentAlignment="{Binding HorizontalContentAlignment}"
|
||||
AllowDrag="{Binding AllowDrag}"
|
||||
AllowSpin="{Binding AllowSpin}"
|
||||
FontFamily="{Binding FontFamily, Mode=OneWay}"
|
||||
FormatString="{Binding FormatString}"
|
||||
InnerLeftContent="{Binding InnerLeftContent}"
|
||||
IsEnabled="{Binding IsEnable}"
|
||||
IsReadOnly="{Binding IsReadOnly}"
|
||||
Maximum="{Binding Maximum}"
|
||||
Minimum="{Binding Minimum}"
|
||||
ParsingNumberStyle="{Binding ParsingNumberStyle}"
|
||||
ShowButtonSpinner="{Binding ShowButtonSpinner}"
|
||||
Step="{Binding Step}"
|
||||
Watermark="{Binding Watermark}"
|
||||
Value="{Binding Value}" />
|
||||
<u:Divider Content="Demo" />
|
||||
</StackPanel>
|
||||
<Grid ColumnDefinitions="*,*" RowDefinitions="100,*">
|
||||
<StackPanel Grid.ColumnSpan="2">
|
||||
<u:Divider Content="Change Right ->" />
|
||||
<u:NumericUIntUpDown
|
||||
Name="numd"
|
||||
Width="{Binding Width}"
|
||||
HorizontalAlignment="{Binding HorizontalAlignment}"
|
||||
HorizontalContentAlignment="{Binding HorizontalContentAlignment}"
|
||||
AllowDrag="{Binding AllowDrag}"
|
||||
AllowSpin="{Binding AllowSpin}"
|
||||
FontFamily="{Binding FontFamily, Mode=OneWay}"
|
||||
FormatString="{Binding FormatString}"
|
||||
InnerLeftContent="{Binding InnerLeftContent}"
|
||||
IsEnabled="{Binding IsEnable}"
|
||||
IsReadOnly="{Binding IsReadOnly}"
|
||||
Maximum="{Binding Maximum}"
|
||||
Minimum="{Binding Minimum}"
|
||||
ParsingNumberStyle="{Binding ParsingNumberStyle}"
|
||||
ShowButtonSpinner="{Binding ShowButtonSpinner}"
|
||||
Step="{Binding Step}"
|
||||
Watermark="{Binding Watermark}"
|
||||
Value="{Binding Value}" />
|
||||
<u:Divider Content="Demo" />
|
||||
</StackPanel>
|
||||
|
||||
<Grid
|
||||
Grid.Row="1"
|
||||
Grid.Column="0"
|
||||
HorizontalAlignment="Left">
|
||||
<StackPanel Grid.Row="1">
|
||||
<u:Divider Content="{Binding #input.Value, StringFormat='Int = {0}'}" />
|
||||
<u:NumericIntUpDown
|
||||
@@ -119,43 +121,50 @@
|
||||
Value="2" />
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
<StackPanel Grid.Column="1" HorizontalAlignment="Left">
|
||||
|
||||
<Label Content="FontFamily" />
|
||||
<TextBox Text="{Binding FontFamily}" />
|
||||
<StackPanel
|
||||
Grid.Row="1"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="Left"
|
||||
Orientation="Vertical">
|
||||
|
||||
<Label Content="AllowDrag" />
|
||||
<CheckBox IsChecked="{Binding AllowDrag}" />
|
||||
<CheckBox Content="AutoWidth" IsChecked="{Binding AutoWidth}" />
|
||||
<u:NumericDoubleUpDown
|
||||
AllowDrag="True"
|
||||
InnerLeftContent="Width"
|
||||
IsEnabled="{Binding !AutoWidth}"
|
||||
Value="{Binding Width}" />
|
||||
|
||||
<Label Content="IsReadOnly" />
|
||||
<CheckBox IsChecked="{Binding IsReadOnly}" />
|
||||
<TextBox InnerLeftContent="FontFamily" Text="{Binding FontFamily}" />
|
||||
|
||||
<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" />
|
||||
<ComboBox ItemsSource="{Binding Array_HorizontalContentAlignment}" SelectedItem="{Binding HorizontalContentAlignment}" />
|
||||
|
||||
<Label Content="InnerLeftContent" />
|
||||
<TextBox Text="{Binding InnerLeftContent}" />
|
||||
<TextBox
|
||||
InnerLeftContent="InnerLeftContent"
|
||||
InnerRightContent="obj"
|
||||
Text="{Binding InnerLeftContent}" />
|
||||
|
||||
<TextBox InnerLeftContent="Watermark" Text="{Binding Watermark}" />
|
||||
|
||||
<Label Content="Watermark" />
|
||||
<TextBox Text="{Binding Watermark}" />
|
||||
|
||||
|
||||
<Label Content="FormatString" />
|
||||
<TextBox
|
||||
MinWidth="100"
|
||||
InnerLeftContent="FormatString"
|
||||
MaxLength="100"
|
||||
Text="{Binding FormatString}" />
|
||||
|
||||
<Label Content="ParsingNumberStyle" />
|
||||
<ComboBox ItemsSource="{Binding Array_ParsingNumberStyle}" SelectedItem="{Binding ParsingNumberStyle}" />
|
||||
|
||||
<CheckBox Content="AllowSpin" IsChecked="{Binding AllowSpin}" />
|
||||
|
||||
<Label Content="AllowSpin" />
|
||||
<CheckBox IsChecked="{Binding AllowSpin}" />
|
||||
|
||||
<Label Content="ShowButtonSpinner" />
|
||||
<CheckBox IsChecked="{Binding ShowButtonSpinner}" />
|
||||
<CheckBox Content="ShowButtonSpinner" IsChecked="{Binding ShowButtonSpinner}" />
|
||||
|
||||
<u:NumericUIntUpDown
|
||||
Name="nudV"
|
||||
@@ -169,12 +178,14 @@
|
||||
|
||||
<u:NumericUIntUpDown InnerLeftContent="Min" Value="{Binding Minimum}" />
|
||||
|
||||
<Label Content="Step" />
|
||||
<Slider Minimum="1" Value="{Binding Step}" />
|
||||
<Label Content="{Binding Step, StringFormat='Step {0}'}" />
|
||||
<Slider
|
||||
Minimum="1"
|
||||
ToolTip.Tip="{Binding Step}"
|
||||
Value="{Binding Step}" />
|
||||
|
||||
<Label Content="IsEnable" />
|
||||
<CheckBox IsChecked="{Binding IsEnable}" />
|
||||
<CheckBox Content="IsEnable" IsChecked="{Binding IsEnable}" />
|
||||
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
</UserControl>
|
||||
@@ -11,11 +11,18 @@ namespace Ursa.Demo.ViewModels;
|
||||
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 string _FontFamily = "Consolas";
|
||||
[ObservableProperty] private bool _AllowDrag = false;
|
||||
[ObservableProperty] private bool _IsReadOnly = false;
|
||||
|
||||
[ObservableProperty] private Array _Array_HorizontalAlignment;
|
||||
[ObservableProperty] private HorizontalAlignment _HorizontalAlignment = HorizontalAlignment.Center;
|
||||
|
||||
[ObservableProperty] private Array _Array_HorizontalContentAlignment;
|
||||
[ObservableProperty] private HorizontalAlignment _HorizontalContentAlignment = HorizontalAlignment.Center;
|
||||
[ObservableProperty] private object? _InnerLeftContent = "obj:0x";
|
||||
@@ -36,12 +43,26 @@ public partial class NumericUpDownDemoViewModel : ObservableObject
|
||||
public NumericUpDownDemoViewModel()
|
||||
{
|
||||
Array_HorizontalContentAlignment = Enum.GetValues(typeof(HorizontalAlignment));
|
||||
Array_HorizontalAlignment = Enum.GetValues(typeof(HorizontalAlignment));
|
||||
Array_ParsingNumberStyle = Enum.GetValues(typeof(NumberStyles));
|
||||
NumericUIntUpDown numericUIntUpDown;
|
||||
TextBox textBox;
|
||||
|
||||
}
|
||||
|
||||
partial void OnAutoWidthChanged(bool value)
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
_oldWidth = Width;
|
||||
Width = double.NaN;
|
||||
}
|
||||
else
|
||||
{
|
||||
Width = _oldWidth;
|
||||
}
|
||||
}
|
||||
|
||||
partial void OnValueChanging(uint oldValue, uint newValue)
|
||||
{
|
||||
Console.WriteLine(oldValue);
|
||||
|
||||
@@ -176,7 +176,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl
|
||||
{
|
||||
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 (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);
|
||||
}
|
||||
@@ -351,12 +355,25 @@ public abstract class NumericUpDownBase<T> : NumericUpDown where T : struct, ICo
|
||||
{
|
||||
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);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<Import Project="../Package.props"/>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<TargetFrameworks>netstandard2.0;net8</TargetFrameworks>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<LangVersion>latest</LangVersion>
|
||||
|
||||
Reference in New Issue
Block a user