Skip to content

Commit

Permalink
(GH-3376) Fix hexadecimal text input
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Nov 9, 2019
1 parent b591e93 commit 46194cb
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/MahApps.Metro/Controls/NumericUpDown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ private static void InterceptManualEnterChangedCallback(DependencyObject depende
}
}

private static readonly Regex RegexStringFormatHexadecimal = new Regex(@"^(?<complexHEX>.*{\d:X\d+}.*)?(?<simpleHEX>X\d+)?$", RegexOptions.Compiled);
private static readonly Regex RegexStringFormatHexadecimal = new Regex(@"^(?<complexHEX>.*{\d\s*:[Xx]\d*}.*)?(?<simpleHEX>[Xx]\d*)?$", RegexOptions.Compiled);
private const string RawRegexNumberString = @"[-+]?(?<![0-9][<DecimalSeparator><GroupSeparator>])[<DecimalSeparator><GroupSeparator>]?[0-9]+(?:[<DecimalSeparator><GroupSeparator>\s][0-9]+)*[<DecimalSeparator><GroupSeparator>]?[0-9]?(?:[eE][-+]?[0-9]+)?(?!\.[0-9])";
private Regex regexNumber = null;
private static readonly Regex RegexHexadecimal = new Regex(@"^([a-fA-F0-9]{1,2}\s?)+$", RegexOptions.Compiled);
Expand Down Expand Up @@ -930,10 +930,11 @@ private static void OnStringFormatChanged(DependencyObject d, DependencyProperty
nud.InternalSetText(nud.Value);
}

var value = (string)e.NewValue;
var format = (string)e.NewValue;

if (!nud.NumericInputMode.HasFlag(NumericInput.Decimal) && !string.IsNullOrEmpty(value) && RegexStringFormatHexadecimal.IsMatch(value))
if (!string.IsNullOrEmpty(format) && RegexStringFormatHexadecimal.IsMatch(format))
{
nud.SetCurrentValue(ParsingNumberStyleProperty, NumberStyles.HexNumber);
nud.SetCurrentValue(NumericInputModeProperty, nud.NumericInputMode | NumericInput.Decimal);
}
}
Expand Down

0 comments on commit 46194cb

Please sign in to comment.