Generic Controls
#13480
Replies: 2 comments
-
|
Making NumericUpDown a Generic Control supporting decimal, double, float, etc. Should be possible in the Avalonia 12 timing. It requires .NET 7+ and I believe the plan is .NET 8 minimum or so? Keeping an eye on this. |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
It sounds like some attempts Ursa has made on |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Generic Controls
This is an idea I've been considering for a while. When C# first came about there were no generics. WPF was mostly implemented without them as well. This is a problem for some controls like the NumericUpDown/NumberBox or even DatePicker.
.NET now has many, many types. These should be used under slightly different scenarios:
doubleordecimalbut also could beint,long, etc. We've currently settled ondecimalas that supports all cases exactly but still requires type conversion in most cases. Not ideal.DateTime,DateTimeOffsetand nowDateOnly. Again, we have to decide what the best type is here and unfortunatley for legacy reasons its DateTime. That isn't great and it now should really be DateOnly but apps may need DateTimeOffset as well..NET is now far enough along I think these problems can be fixed by introducing a new concept called "Generic Controls".
NumberBox
Note: This assumes a port from WinUI3 for this control first. That is something I mean to do eventually along with making the number parsing pipeline customizable which wasn't supported in that control originally.
With .NET 7 we now have the INumber interface. This combined with a new concept for generic controls can solve this problem in the case of a NumberBox.
This would allow the control to support ANY numeric type. In addition, you have a version you can use with no type parameter that will default to decimal. This seems like the best of both worlds and can be used anywhere.
Calendar
Calendar-related controls can't get this functionality yet because there is no IDate interface in .NET yet. My bet is that is something that would be accepted upstream though. It is also very easy to do.
Upstream discussion: dotnet/runtime#97622
Feedback
What are everyone's thoughts to this idea?
Beta Was this translation helpful? Give feedback.
All reactions