diff --git a/demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml b/demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml index 77b0def..5f7355d 100644 --- a/demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml +++ b/demo/Ursa.Demo/Pages/NumericUpDownDemo.axaml @@ -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"> @@ -20,33 +20,35 @@ - - - - - - - + + + + + + + - - - + \ No newline at end of file diff --git a/demo/Ursa.Demo/ViewModels/NumericUpDownDemoViewModel.cs b/demo/Ursa.Demo/ViewModels/NumericUpDownDemoViewModel.cs index 9cf7651..aa8abee 100644 --- a/demo/Ursa.Demo/ViewModels/NumericUpDownDemoViewModel.cs +++ b/demo/Ursa.Demo/ViewModels/NumericUpDownDemoViewModel.cs @@ -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); diff --git a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs index 33f496b..40df9e3 100644 --- a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs +++ b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs @@ -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 : 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 : 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; } diff --git a/src/Ursa/Ursa.csproj b/src/Ursa/Ursa.csproj index 448ddec..c60174b 100644 --- a/src/Ursa/Ursa.csproj +++ b/src/Ursa/Ursa.csproj @@ -3,7 +3,7 @@ - netstandard2.0 + netstandard2.0;net8 enable enable latest