Add Int64Displayer control for long type support (#811)

This commit is contained in:
Copilot
2025-11-07 21:35:52 +08:00
committed by GitHub
parent d495c98967
commit 6941cef2a7
3 changed files with 28 additions and 0 deletions

View File

@@ -14,6 +14,7 @@
<StackPanel HorizontalAlignment="Left">
<Button Command="{Binding IncreaseCommand}">Change</Button>
<u:Int32Displayer Value="{Binding Value}" />
<u:Int64Displayer Value="{Binding LongValue}" />
<u:DoubleDisplayer StringFormat="N2" Value="{Binding DoubleValue}" />
<u:DateDisplay
FontSize="30"
@@ -21,6 +22,7 @@
Value="{Binding DateValue}" />
<TextBlock Text="Selectable: "></TextBlock>
<u:Int32Displayer Value="{Binding Value}" IsSelectable="True" />
<u:Int64Displayer Value="{Binding LongValue}" IsSelectable="True" />
<u:DoubleDisplayer StringFormat="N2" Value="{Binding DoubleValue}" IsSelectable="True" />
<u:DateDisplay
FontSize="30"

View File

@@ -8,6 +8,7 @@ namespace Ursa.Demo.ViewModels;
public partial class NumberDisplayerDemoViewModel: ObservableObject
{
[ObservableProperty] private int _value;
[ObservableProperty] private long _longValue;
[ObservableProperty] private double _doubleValue;
[ObservableProperty] private DateTime _dateValue;
public ICommand IncreaseCommand { get; }
@@ -15,6 +16,7 @@ public partial class NumberDisplayerDemoViewModel: ObservableObject
{
IncreaseCommand = new RelayCommand(OnChange);
Value = 0;
LongValue = 0L;
DoubleValue = 0d;
DateValue = DateTime.Now;
}
@@ -23,6 +25,7 @@ public partial class NumberDisplayerDemoViewModel: ObservableObject
{
Random r = new Random();
Value = r.Next(int.MaxValue);
LongValue = ((long)r.Next(int.MaxValue)) * 1000 + r.Next(1000);
DoubleValue = r.NextDouble() * 100000;
DateValue = DateTime.Today.AddDays(r.Next(1000));
}

View File

@@ -25,6 +25,29 @@ public class Int32Displayer : NumberDisplayer<int>
}
}
public class Int64Displayer : NumberDisplayer<long>
{
protected override Type StyleKeyOverride { get; } = typeof(NumberDisplayerBase);
protected override InterpolatingAnimator<long> GetAnimator()
{
return new LongAnimator();
}
private class LongAnimator : InterpolatingAnimator<long>
{
public override long Interpolate(double progress, long oldValue, long newValue)
{
return oldValue + (long)((newValue - oldValue) * progress);
}
}
protected override string GetString(long value)
{
return value.ToString(StringFormat);
}
}
public class DoubleDisplayer : NumberDisplayer<double>
{
protected override Type StyleKeyOverride { get; } = typeof(NumberDisplayerBase);