feat: add a lot of other types.
This commit is contained in:
@@ -8,14 +8,19 @@
|
|||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<StackPanel>
|
<UserControl.Styles>
|
||||||
<u:IntUpDown Name="input" Step="1" Value="2" Watermark="Input Value" />
|
<Style Selector=":is(u|NumericUpDown)">
|
||||||
|
<Setter Property="Width" Value="240"></Setter>
|
||||||
|
</Style>
|
||||||
|
</UserControl.Styles>
|
||||||
|
<StackPanel HorizontalAlignment="Left">
|
||||||
|
<u:NumericIntUpDown Name="input" Step="1" Value="2" Watermark="Input Value" />
|
||||||
<TextBlock Text="{Binding #input.Value}" ></TextBlock>
|
<TextBlock Text="{Binding #input.Value}" ></TextBlock>
|
||||||
<u:DoubleUpDown Name="inputDouble" Step="0.5" Value="3.1" EmptyInputValue="1"></u:DoubleUpDown>
|
<u:NumericDoubleUpDown Name="inputDouble" Step="0.5" Value="3.1" EmptyInputValue="1"></u:NumericDoubleUpDown>
|
||||||
<TextBlock Text="{Binding #inputDouble.Value}"></TextBlock>
|
<TextBlock Text="{Binding #inputDouble.Value}"></TextBlock>
|
||||||
<u:ByteUpDown Name="inputByte" Step="1" Value="3" EmptyInputValue="1"></u:ByteUpDown>
|
<u:NumericByteUpDown Name="inputByte" Step="1" Value="3" EmptyInputValue="1"></u:NumericByteUpDown>
|
||||||
<TextBlock Text="{Binding #inputByte.Value}"></TextBlock>
|
<TextBlock Text="{Binding #inputByte.Value}"></TextBlock>
|
||||||
<TextBlock Text="Drag"></TextBlock>
|
<TextBlock Text="Drag"></TextBlock>
|
||||||
<u:IntUpDown Step="1" Value="2" Watermark="Input Value" TextEditable="False" />
|
<u:NumericIntUpDown Step="1" Value="2" Watermark="Input Value" TextEditable="False" />
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -4,15 +4,15 @@ using Avalonia.Utilities;
|
|||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
public class IntUpDown : NumericUpDownBase<int>
|
public class NumericIntUpDown : NumericUpDownBase<int>
|
||||||
{
|
{
|
||||||
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
static IntUpDown()
|
static NumericIntUpDown()
|
||||||
{
|
{
|
||||||
MaximumProperty.OverrideDefaultValue<IntUpDown>(int.MaxValue);
|
MaximumProperty.OverrideDefaultValue<NumericIntUpDown>(int.MaxValue);
|
||||||
MinimumProperty.OverrideDefaultValue<IntUpDown>(int.MinValue);
|
MinimumProperty.OverrideDefaultValue<NumericIntUpDown>(int.MinValue);
|
||||||
StepProperty.OverrideDefaultValue<IntUpDown>(1);
|
StepProperty.OverrideDefaultValue<NumericIntUpDown>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ParseText(string? text, out int? number)
|
protected override bool ParseText(string? text, out int? number)
|
||||||
@@ -31,15 +31,15 @@ public class IntUpDown : NumericUpDownBase<int>
|
|||||||
protected override int? Minus(int? a, int? b) => a - b;
|
protected override int? Minus(int? a, int? b) => a - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class DoubleUpDown : NumericUpDownBase<double>
|
public class NumericDoubleUpDown : NumericUpDownBase<double>
|
||||||
{
|
{
|
||||||
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
static DoubleUpDown()
|
static NumericDoubleUpDown()
|
||||||
{
|
{
|
||||||
MaximumProperty.OverrideDefaultValue<DoubleUpDown>(double.MaxValue);
|
MaximumProperty.OverrideDefaultValue<NumericDoubleUpDown>(double.MaxValue);
|
||||||
MinimumProperty.OverrideDefaultValue<DoubleUpDown>(double.MinValue);
|
MinimumProperty.OverrideDefaultValue<NumericDoubleUpDown>(double.MinValue);
|
||||||
StepProperty.OverrideDefaultValue<DoubleUpDown>(1);
|
StepProperty.OverrideDefaultValue<NumericDoubleUpDown>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ParseText(string? text, out double? number)
|
protected override bool ParseText(string? text, out double? number)
|
||||||
@@ -59,15 +59,15 @@ public class DoubleUpDown : NumericUpDownBase<double>
|
|||||||
protected override double? Minus(double? a, double? b) => a - b;
|
protected override double? Minus(double? a, double? b) => a - b;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ByteUpDown : NumericUpDownBase<byte>
|
public class NumericByteUpDown : NumericUpDownBase<byte>
|
||||||
{
|
{
|
||||||
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
static ByteUpDown()
|
static NumericByteUpDown()
|
||||||
{
|
{
|
||||||
MaximumProperty.OverrideDefaultValue<ByteUpDown>(byte.MaxValue);
|
MaximumProperty.OverrideDefaultValue<NumericByteUpDown>(byte.MaxValue);
|
||||||
MinimumProperty.OverrideDefaultValue<ByteUpDown>(byte.MinValue);
|
MinimumProperty.OverrideDefaultValue<NumericByteUpDown>(byte.MinValue);
|
||||||
StepProperty.OverrideDefaultValue<ByteUpDown>(1);
|
StepProperty.OverrideDefaultValue<NumericByteUpDown>(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool ParseText(string? text, out byte? number)
|
protected override bool ParseText(string? text, out byte? number)
|
||||||
@@ -84,4 +84,194 @@ public class ByteUpDown : NumericUpDownBase<byte>
|
|||||||
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<sbyte>
|
||||||
|
{
|
||||||
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
|
static NumericSByteUpDown()
|
||||||
|
{
|
||||||
|
MaximumProperty.OverrideDefaultValue<NumericSByteUpDown>(sbyte.MaxValue);
|
||||||
|
MinimumProperty.OverrideDefaultValue<NumericSByteUpDown>(sbyte.MinValue);
|
||||||
|
StepProperty.OverrideDefaultValue<NumericSByteUpDown>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ParseText(string? text, out sbyte? number)
|
||||||
|
{
|
||||||
|
var result = sbyte.TryParse(text, ParsingNumberStyle, NumberFormat, out var value);
|
||||||
|
number = value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string? ValueToString(sbyte? value) => value?.ToString(FormatString, NumberFormat);
|
||||||
|
|
||||||
|
protected override sbyte Zero => 0;
|
||||||
|
|
||||||
|
protected override sbyte? Add(sbyte? a, sbyte? b) => (sbyte?) (a + b);
|
||||||
|
|
||||||
|
protected override sbyte? Minus(sbyte? a, sbyte? b) => (sbyte?) (a - b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NumericShortUpDown : NumericUpDownBase<short>
|
||||||
|
{
|
||||||
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
|
static NumericShortUpDown()
|
||||||
|
{
|
||||||
|
MaximumProperty.OverrideDefaultValue<NumericShortUpDown>(short.MaxValue);
|
||||||
|
MinimumProperty.OverrideDefaultValue<NumericShortUpDown>(short.MinValue);
|
||||||
|
StepProperty.OverrideDefaultValue<NumericShortUpDown>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ParseText(string? text, out short? number)
|
||||||
|
{
|
||||||
|
var result = short.TryParse(text, ParsingNumberStyle, NumberFormat, out var value);
|
||||||
|
number = value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string? ValueToString(short? value) => value?.ToString(FormatString, NumberFormat);
|
||||||
|
|
||||||
|
protected override short Zero => 0;
|
||||||
|
|
||||||
|
protected override short? Add(short? a, short? b) => (short?) (a + b);
|
||||||
|
|
||||||
|
protected override short? Minus(short? a, short? b) => (short?) (a - b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NumericUShortUpDown : NumericUpDownBase<ushort>
|
||||||
|
{
|
||||||
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
|
static NumericUShortUpDown()
|
||||||
|
{
|
||||||
|
MaximumProperty.OverrideDefaultValue<NumericUShortUpDown>(ushort.MaxValue);
|
||||||
|
MinimumProperty.OverrideDefaultValue<NumericUShortUpDown>(ushort.MinValue);
|
||||||
|
StepProperty.OverrideDefaultValue<NumericUShortUpDown>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ParseText(string? text, out ushort? number)
|
||||||
|
{
|
||||||
|
var result = ushort.TryParse(text, ParsingNumberStyle, NumberFormat, out var value);
|
||||||
|
number = value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string? ValueToString(ushort? value) => value?.ToString(FormatString, NumberFormat);
|
||||||
|
|
||||||
|
protected override ushort Zero => 0;
|
||||||
|
|
||||||
|
protected override ushort? Add(ushort? a, ushort? b) => (ushort?) (a + b);
|
||||||
|
|
||||||
|
protected override ushort? Minus(ushort? a, ushort? b) => (ushort?) (a - b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NumericLongUpDown : NumericUpDownBase<long>
|
||||||
|
{
|
||||||
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
|
static NumericLongUpDown()
|
||||||
|
{
|
||||||
|
MaximumProperty.OverrideDefaultValue<NumericLongUpDown>(long.MaxValue);
|
||||||
|
MinimumProperty.OverrideDefaultValue<NumericLongUpDown>(long.MinValue);
|
||||||
|
StepProperty.OverrideDefaultValue<NumericLongUpDown>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ParseText(string? text, out long? number)
|
||||||
|
{
|
||||||
|
var result = long.TryParse(text, ParsingNumberStyle, NumberFormat, out var value);
|
||||||
|
number = value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string? ValueToString(long? value) => value?.ToString(FormatString, NumberFormat);
|
||||||
|
|
||||||
|
protected override long Zero => 0;
|
||||||
|
|
||||||
|
protected override long? Add(long? a, long? b) => a + b;
|
||||||
|
|
||||||
|
protected override long? Minus(long? a, long? b) => a - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NumericULongUpDown : NumericUpDownBase<ulong>
|
||||||
|
{
|
||||||
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
|
static NumericULongUpDown()
|
||||||
|
{
|
||||||
|
MaximumProperty.OverrideDefaultValue<NumericULongUpDown>(ulong.MaxValue);
|
||||||
|
MinimumProperty.OverrideDefaultValue<NumericULongUpDown>(ulong.MinValue);
|
||||||
|
StepProperty.OverrideDefaultValue<NumericULongUpDown>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ParseText(string? text, out ulong? number)
|
||||||
|
{
|
||||||
|
var result = ulong.TryParse(text, ParsingNumberStyle, NumberFormat, out var value);
|
||||||
|
number = value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string? ValueToString(ulong? value) => value?.ToString(FormatString, NumberFormat);
|
||||||
|
|
||||||
|
protected override ulong Zero => 0;
|
||||||
|
|
||||||
|
protected override ulong? Add(ulong? a, ulong? b) => a + b;
|
||||||
|
|
||||||
|
protected override ulong? Minus(ulong? a, ulong? b) => a - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NumericFloatUpDown : NumericUpDownBase<float>
|
||||||
|
{
|
||||||
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
|
static NumericFloatUpDown()
|
||||||
|
{
|
||||||
|
MaximumProperty.OverrideDefaultValue<NumericFloatUpDown>(float.MaxValue);
|
||||||
|
MinimumProperty.OverrideDefaultValue<NumericFloatUpDown>(float.MinValue);
|
||||||
|
StepProperty.OverrideDefaultValue<NumericFloatUpDown>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ParseText(string? text, out float? number)
|
||||||
|
{
|
||||||
|
var result = float.TryParse(text, ParsingNumberStyle, NumberFormat, out var value);
|
||||||
|
number = value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string? ValueToString(float? value) => value?.ToString(FormatString, NumberFormat);
|
||||||
|
|
||||||
|
protected override float Zero => 0;
|
||||||
|
|
||||||
|
protected override float? Add(float? a, float? b) => a + b;
|
||||||
|
|
||||||
|
protected override float? Minus(float? a, float? b) => a - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class NumericDecimalUpDown : NumericUpDownBase<decimal>
|
||||||
|
{
|
||||||
|
protected override Type StyleKeyOverride { get; } = typeof(NumericUpDown);
|
||||||
|
|
||||||
|
static NumericDecimalUpDown()
|
||||||
|
{
|
||||||
|
MaximumProperty.OverrideDefaultValue<NumericDecimalUpDown>(decimal.MaxValue);
|
||||||
|
MinimumProperty.OverrideDefaultValue<NumericDecimalUpDown>(decimal.MinValue);
|
||||||
|
StepProperty.OverrideDefaultValue<NumericDecimalUpDown>(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override bool ParseText(string? text, out decimal? number)
|
||||||
|
{
|
||||||
|
var result = decimal.TryParse(text, ParsingNumberStyle, NumberFormat, out var value);
|
||||||
|
number = value;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override string? ValueToString(decimal? value) => value?.ToString(FormatString, NumberFormat);
|
||||||
|
|
||||||
|
protected override decimal Zero => 0;
|
||||||
|
|
||||||
|
protected override decimal? Add(decimal? a, decimal? b) => a + b;
|
||||||
|
|
||||||
|
protected override decimal? Minus(decimal? a, decimal? b) => a - b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user