You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
NumberBox : Should use either double or decimal but also could be int, long, etc. We've currently settled on decimal as that supports all cases exactly but still requires type conversion in most cases. Not ideal.
Calendar : .NET has DateTime, DateTimeOffset and now DateOnly. 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.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
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:
double
ordecimal
but also could beint
,long
, etc. We've currently settled ondecimal
as that supports all cases exactly but still requires type conversion in most cases. Not ideal.DateTime
,DateTimeOffset
and 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.
Feedback
What are everyone's thoughts to this idea?
Beta Was this translation helpful? Give feedback.
All reactions