From 21e6a2e996a9a2ac2530cb4c9149d97f61ca6b79 Mon Sep 17 00:00:00 2001 From: heartacker Date: Wed, 20 Mar 2024 15:48:33 +0800 Subject: [PATCH] add NumericUIntUpDown --- src/Ursa/Controls/NumericUpDown/IntUpDown.cs | 50 ++++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/Ursa/Controls/NumericUpDown/IntUpDown.cs b/src/Ursa/Controls/NumericUpDown/IntUpDown.cs index 4feedcb..218a9dd 100644 --- a/src/Ursa/Controls/NumericUpDown/IntUpDown.cs +++ b/src/Ursa/Controls/NumericUpDown/IntUpDown.cs @@ -18,7 +18,10 @@ public class NumericIntUpDown : NumericUpDownBase protected override bool ParseText(string? text, out int number) => int.TryParse(text, ParsingNumberStyle, NumberFormat, out number); - protected override string? ValueToString(int? value) => value?.ToString(FormatString, NumberFormat); + protected override string? ValueToString(int? value) + { + return value?.ToString(FormatString, NumberFormat); + } protected override int Zero => 0; @@ -27,6 +30,34 @@ public class NumericIntUpDown : NumericUpDownBase protected override int? Minus(int? a, int? b) => a - b; } +public class NumericUIntUpDown : NumericUpDownBase +{ + protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown); + + static NumericUIntUpDown() + { + MaximumProperty.OverrideDefaultValue(uint.MaxValue); + MinimumProperty.OverrideDefaultValue(uint.MinValue); + StepProperty.OverrideDefaultValue(0); + } + + protected override bool ParseText(string? text, out uint number) + { + return uint.TryParse(text, ParsingNumberStyle, NumberFormat, out number); + } + + protected override string? ValueToString(uint? value) + { + return value?.ToString(FormatString, NumberFormat); + } + + protected override uint Zero => 0; + + protected override uint? Add(uint? a, uint? b) => a + b; + + protected override uint? Minus(uint? a, uint? b) => a - b; +} + public class NumericDoubleUpDown : NumericUpDownBase { protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown); @@ -68,9 +99,9 @@ public class NumericByteUpDown : NumericUpDownBase protected override byte Zero => 0; - protected override byte? Add(byte? a, byte? b) => (byte?) (a + b); + protected override byte? Add(byte? a, byte? b) => (byte?)(a + b); - protected override byte? Minus(byte? a, byte? b) => (byte?) (a - b); + protected override byte? Minus(byte? a, byte? b) => (byte?)(a - b); } public class NumericSByteUpDown : NumericUpDownBase @@ -91,9 +122,9 @@ public class NumericSByteUpDown : NumericUpDownBase protected override sbyte Zero => 0; - protected override sbyte? Add(sbyte? a, sbyte? b) => (sbyte?) (a + b); + protected override sbyte? Add(sbyte? a, sbyte? b) => (sbyte?)(a + b); - protected override sbyte? Minus(sbyte? a, sbyte? b) => (sbyte?) (a - b); + protected override sbyte? Minus(sbyte? a, sbyte? b) => (sbyte?)(a - b); } public class NumericShortUpDown : NumericUpDownBase @@ -114,9 +145,9 @@ public class NumericShortUpDown : NumericUpDownBase protected override short Zero => 0; - protected override short? Add(short? a, short? b) => (short?) (a + b); + protected override short? Add(short? a, short? b) => (short?)(a + b); - protected override short? Minus(short? a, short? b) => (short?) (a - b); + protected override short? Minus(short? a, short? b) => (short?)(a - b); } public class NumericUShortUpDown : NumericUpDownBase @@ -137,9 +168,9 @@ public class NumericUShortUpDown : NumericUpDownBase protected override ushort Zero => 0; - protected override ushort? Add(ushort? a, ushort? b) => (ushort?) (a + b); + protected override ushort? Add(ushort? a, ushort? b) => (ushort?)(a + b); - protected override ushort? Minus(ushort? a, ushort? b) => (ushort?) (a - b); + protected override ushort? Minus(ushort? a, ushort? b) => (ushort?)(a - b); } public class NumericLongUpDown : NumericUpDownBase @@ -233,4 +264,3 @@ public class NumericDecimalUpDown : NumericUpDownBase protected override decimal? Minus(decimal? a, decimal? b) => a - b; } -