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

NumericUpDown: When Changing String Format From Hexadecimal To Any Other Non-Hexadecimal String Format, The Input Will Always Be Parsed As Hexadecimal #4499

Open
BenMendel opened this issue Jul 1, 2024 · 0 comments
Labels

Comments

@BenMendel
Copy link

Once you changed the "StringFormat" property from hexadecimal format to any different format, the property "ParsingNumberStyle" will be set on "HexNumber" and cannot be changed. This causes for decimal numbers to be parsed as hexadecimal.

Steps to reproduce

Create this control for example:

<mah:NumericUpDown Margin="10" Maximum="70000"
                   Minimum="1"
                   Interval="1">
    <mah:NumericUpDown.ContextMenu>
        <ContextMenu >
            <MenuItem x:Name="IndexHexMenuItem" Header="Hex" IsCheckable="True"/>
        </ContextMenu>
    </mah:NumericUpDown.ContextMenu>
    
    <mah:NumericUpDown.Style>
        <Style TargetType="mah:NumericUpDown">
            <Setter Property="StringFormat"
                    Value="" />
            <Setter Property="NumericInputMode"
                    Value="Numbers" />
            <Setter Property="ParsingNumberStyle"
                    Value="Any" />
            <Style.Triggers>
                <DataTrigger Binding="{Binding ElementName=IndexHexMenuItem, Path=IsChecked}" Value="True">
                    <Setter Property="StringFormat"
                            Value="{}0x{0:X}" />
                </DataTrigger>
            </Style.Triggers>
        </Style>
    </mah:NumericUpDown.Style>
</mah:NumericUpDown>
  1. Enter the text "10", then hit "Enter" to update the value
  2. Right click in the textbox, hit the "Hex" button, the "10" text is changed to "0xA" (the "Value" property remained the same - 10).
  3. Right click in the textbox, hit the "Hex" button again, the text is changed back to "10"
  4. Enter the text "10", then hit "Enter" to update the value, and the value and the text are changed to "16"

Expected behavior

When the "Hex" is changed from checked to unchecked (I.e., the "StringFormat" property is changed from "{}0x{0:X}" to string.Empty), the parsing should return to normal decimal numbers (I.e., the "ParsingNumberStyle" should also change from "HexNumbers" to "Any"), and not hexadecimals.
E.g., enter the text "10", click enter. I should see the value "10" as the "Value" property.

Actual behavior

Input text is parsed as hexadecimal.
E.g., enter the text "10", click enter. I see the value "16" as the "Value" property.

Environment

MahApps.Metro version: v2.4.10
Windows build number: Win11 Pro 23H2 [OS Build 22631.3810]
Visual Studio: 2022 17.10.3
Target Framework: .Net 7

Screenshots

@BenMendel BenMendel added the Bug label Jul 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant