From af48e6f711ecdeae4c3a921656531e61703b70b0 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Tue, 25 Dec 2018 16:11:03 +0200 Subject: Implemented negative numbers support for touch numeric up down. --- .../Tango.Touch/Controls/TouchNumericTextBox.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/Tango.Touch/Controls/TouchNumericTextBox.cs') diff --git a/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericTextBox.cs b/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericTextBox.cs index aee5fae26..fa57169f3 100644 --- a/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericTextBox.cs +++ b/Software/Visual_Studio/Tango.Touch/Controls/TouchNumericTextBox.cs @@ -22,8 +22,8 @@ namespace Tango.Touch.Controls private bool _prevent_text_change; private TextBlock _text_block; private double _lastValue; - Regex regex_integer = new Regex(@"^[0-9]*(?:[0-9]*)?$"); - Regex regex_double = new Regex(@"^[0-9]*(?:\.[0-9]*)?$"); + Regex regex_integer = new Regex(@"^-?[0-9]\d*(\d+)?$"); + Regex regex_double = new Regex(@"^-?[0-9]\d*(\.\d+)?$"); public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble, typeof(DoubleValueChangedEventHandler), typeof(TouchNumericTextBox)); public event DoubleValueChangedEventHandler ValueChanged @@ -212,6 +212,17 @@ namespace Tango.Touch.Controls return; } + if (e.Text == "-" && !_text_box.Text.Contains("-")) + { + e.Handled = false; + return; + } + else if (e.Text == "-") + { + e.Handled = true; + return; + } + if (HasDecimalPoint) { e.Handled = !regex_double.IsMatch(e.Text); -- cgit v1.3.1