Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle NumericUpDown percentage StringFormat correctly #3678

Merged
merged 8 commits into from
Nov 9, 2019

Conversation

punker76
Copy link
Member

@punker76 punker76 commented Nov 6, 2019

Describe the changes you have made to improve this project

The current behavior for e.g. percentage text input with StringFotmat like P0 or {0:0.00%} converts the input one-to-one to the value:

100% = 100

This is not what the user expects, because the .Net default works different:

100% = 1

So this PR changes this behavior to the .Net default one.

Unit test

  • ShouldConvertTextInputWithPercentageStringFormat
  • ShouldConvertTextInputWithPermilleStringFormat
  • ShouldFormatValueInput

Additional context

  • If the stringformat is HEX the control has to accept [a..f] as Input as well.
  • The DemoApp crashes on an invalid (Hex) Stringformat.

mahapps_numericupdown

Closed Issues

Closes #3376

/cc @mgnslndh @timunie

@punker76 punker76 added this to the 2.0.0 milestone Nov 6, 2019
@punker76 punker76 changed the title Handle NumericUpDown percentage StringFormat correctly WIP Handle NumericUpDown percentage StringFormat correctly Nov 6, 2019
Copy link
Collaborator

@timunie timunie left a comment

Choose a reason for hiding this comment

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

@punker76 I'll have a look at this and let you know if I have any issues with the new implementation.

src/MahApps.Metro/Controls/NumericUpDown.cs Outdated Show resolved Hide resolved
@timunie
Copy link
Collaborator

timunie commented Nov 6, 2019

Hi @punker76

some more thoughts on your PR:

  • Should we derivide from TextBox instead of control? That way some Properties would be implemented by default
  • If the stringformat is HEX the control has to accept [a..f] as Input as well.
  • Is a double- value precise enough? That way you cannot use decimal or ulong - values.
  • The DemoApp crashes on an invalid Stringformat. Is there a way to handle this? Should we handle this?

Happy coding and a 💯 times thanks.
Tim

@timunie
Copy link
Collaborator

timunie commented Nov 7, 2019

Good morning @punker76 ,

  • Is a double- value precise enough? That way you cannot use decimal or ulong - values.

one addition: if we change the basetype to decimal we will also solve #2923 (it was closed in the past with a note that this would be a breaking change, we have a breaking change right now 😄 ) and #3673 .

Happy coding
Tim

@punker76 punker76 force-pushed the 3376_NumericUpDown_StringFormat branch 2 times, most recently from 97258c7 to 920bd5b Compare November 7, 2019 15:12
The current behavior for e.g. percentage text input with StringFotmat like P0 or {0:0.00%} converts the input one-to-one to the value:

100% = 100

This is not what the user expects, because the .Net default works different:

100% = 1

So this PR changes this behavior to the .Net default one.
@punker76 punker76 force-pushed the 3376_NumericUpDown_StringFormat branch from 920bd5b to f4d8680 Compare November 8, 2019 15:51
@punker76 punker76 changed the title WIP Handle NumericUpDown percentage StringFormat correctly Handle NumericUpDown percentage StringFormat correctly Nov 9, 2019
@punker76 punker76 merged commit b5c8f9c into develop Nov 9, 2019
@punker76 punker76 deleted the 3376_NumericUpDown_StringFormat branch November 9, 2019 18:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

NumericUpDown StringFormat doesn't handle percentages correctly.
3 participants