From 46194cb3d221153f7755e20caba632ac3b47e497 Mon Sep 17 00:00:00 2001 From: punker76 Date: Sat, 9 Nov 2019 19:24:40 +0100 Subject: [PATCH] (GH-3376) Fix hexadecimal text input --- src/MahApps.Metro/Controls/NumericUpDown.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/MahApps.Metro/Controls/NumericUpDown.cs b/src/MahApps.Metro/Controls/NumericUpDown.cs index db5d11c1d1..f6fc26c9c9 100644 --- a/src/MahApps.Metro/Controls/NumericUpDown.cs +++ b/src/MahApps.Metro/Controls/NumericUpDown.cs @@ -187,7 +187,7 @@ private static void InterceptManualEnterChangedCallback(DependencyObject depende } } - private static readonly Regex RegexStringFormatHexadecimal = new Regex(@"^(?.*{\d:X\d+}.*)?(?X\d+)?$", RegexOptions.Compiled); + private static readonly Regex RegexStringFormatHexadecimal = new Regex(@"^(?.*{\d\s*:[Xx]\d*}.*)?(?[Xx]\d*)?$", RegexOptions.Compiled); private const string RawRegexNumberString = @"[-+]?(?])[]?[0-9]+(?:[\s][0-9]+)*[]?[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); @@ -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); } }