Skip to content

Conversation

@dotMorten
Copy link
Owner

@dotMorten dotMorten commented Aug 21, 2025

Ports WinUI's NumberBox to NumberBox<T> to allow for any numeric datatype. Exposes two out of the box: NumberBoxDecimal and NumberBoxInt32 but you can extend with your own by creating the class:

public class NumberBoxFloat : NumberBox<float>
{
     public NumberBoxFloat() => DefaultStyleKey = typeof(NumberBoxFloat);
} 

and duplicating the control template from the other controls and updating the target type.

Note: To be able to assign Decimal values to the NumberBoxDecimal control, it can't be done in XAML (although x:Bind works). Support for decimal values is a limitation in the Windows App SDK and is supposed to be addressed in v1.8, but is currently not available in 1.8preview1 (see microsoft/WindowsAppSDK#5756)

@dotMorten dotMorten self-assigned this Aug 21, 2025
@dotMorten dotMorten requested a review from Copilot August 21, 2025 14:53

This comment was marked as outdated.

@dotMorten dotMorten requested a review from Copilot August 26, 2025 05:57

This comment was marked as outdated.

@dotMorten dotMorten requested a review from Copilot August 26, 2025 06:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a generic NumberBox control (NumberBox<T>) that allows for any numeric datatype, replacing the existing WinUI NumberBox that was limited to double values. The PR includes implementations for decimal and integer types (NumberBoxDecimal and NumberBoxInt32), as well as extensive localization resources and a sample application demonstrating the functionality.

  • Upgrades target framework from .NET 6 to .NET 8 with C# preview features
  • Adds generic NumberBox implementation with strongly typed values
  • Includes comprehensive localization resources for over 60 languages

Reviewed Changes

Copilot reviewed 105 out of 105 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
WinUIEx.csproj Updates target framework to .NET 8 and enables package validation
NumberBoxes.xaml.cs Implements sample page with view model for testing NumberBox controls
NumberBoxes.xaml XAML layout demonstrating the new NumberBox controls with property bindings
Generic.xaml References the new NumberBox resource dictionary
ResourceAccessor.cs Internal utility class for accessing localized string resources
Strings/*/Resources.resw Comprehensive localization files for NumberBox automation and status messages

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@dotMorten
Copy link
Owner Author

dotMorten commented Aug 26, 2025

@MPITech I would appreciate if you could try the latest version out. It handles un-set values using Nullable<Decimal> for the Value property so that you can clear the property or bind un-set values. As usual the latest test build is in the actions tab: https://github.com/dotMorten/WinUIEx/actions/runs/17229488671
Note if you're binding non-nullable decimal, to set AllowNull="False" or two-way bindings will fail

@MPITech
Copy link

MPITech commented Aug 26, 2025

@MPITech I would appreciate if you could try the latest version out. It handles un-set values using Nullable<Decimal> for the Value property so that you can clear the property or bind un-set values. As usual the latest test build is in the actions tab: https://github.com/dotMorten/WinUIEx/actions/runs/17229488671 Note if you're binding non-nullable decimal, to set AllowNull="False" or two-way bindings will fail

haha wrong account the first time.

This is a welcome change, since most of my bound fields were nullable decimals and would have required a converter to bind. Will check it out within 24 hours.

@MPITech
Copy link

MPITech commented Aug 27, 2025

@dotMorten This looks pretty good. I checked the following when bound to a nullable decimal property to/from MariaDB using EF Core and all worked well:

  • Saving a null and reloading.
  • Saving a 2 and 4-digit decimal value and reloading.
  • Saving a round number. I entered "2000.00" and when focus is lost, it changes to "2000" and restores as "2000". I'm not sure if the default NumberBox has that same behavior or if it keeps "2000.00", it may be worth double-checking. A NumberFormatter would probably enforce that if needed I guess.

I have some additional suggestions I will file in Issues. But this is a good change.

@dotMorten dotMorten merged commit d207dd8 into main Aug 27, 2025
1 check passed
@dotMorten dotMorten deleted the NumberBox branch August 27, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants