From 7ed0167c4e80950be020d81daca9af7e1d60ce24 Mon Sep 17 00:00:00 2001 From: Jake Norbut Date: Tue, 22 May 2018 17:30:00 -0500 Subject: [PATCH] Qty button mouse behavior --- .../Extensions/TextElement/TextBoxBehavior.cs | 51 +++++++++++++++++++ .../spark/view/Spark/Ladder/LadderView.xaml | 4 +- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/client/spark/view/Extensions/TextElement/TextBoxBehavior.cs b/src/client/spark/view/Extensions/TextElement/TextBoxBehavior.cs index 7ff0aee1f..8c7cac725 100644 --- a/src/client/spark/view/Extensions/TextElement/TextBoxBehavior.cs +++ b/src/client/spark/view/Extensions/TextElement/TextBoxBehavior.cs @@ -1,4 +1,5 @@ using mbts.utils; +using System; using System.Windows; using System.Windows.Controls; using System.Windows.Data; @@ -166,5 +167,55 @@ namespace mbts.ui { public static TextBoxInputFilter GetInputFilter(DependencyObject d) => d.GetValue(InputFilterProperty) as TextBoxInputFilter; public static void SetInputFilter(DependencyObject d, TextBoxInputFilter value) => d.SetValue(InputFilterProperty, value); #endregion + + #region + public static readonly DependencyProperty DecrementOnLeftMouseButtonProperty = DependencyProperty.RegisterAttached( + "DecrementOnLeftMouseButton", typeof(bool), typeof(TextBoxBehavior), new PropertyMetadata(false, DecrementOnLeftMouseButtonPropertyChanged) + ); + + public static bool GetDecrementOnLeftMouseButton(TextBox element) { return (bool)element.GetValue(DecrementOnLeftMouseButtonProperty); } + public static void SetDecrementOnLeftMouseButton(TextBox element, bool value) { element.SetValue(DecrementOnLeftMouseButtonProperty, value); } + + + private static void DecrementOnLeftMouseButtonPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { + var text_box = d as TextBox; + if(text_box != null) { + if ((bool)e.NewValue) { + text_box.PreviewMouseLeftButtonDown += OnMouseLeftButtonDownDecrementValue; + text_box.PreviewMouseRightButtonDown += OnMouseRightButtonDownIncrementValue; + } else { + text_box.PreviewMouseLeftButtonDown -= OnMouseLeftButtonDownDecrementValue; + text_box.PreviewMouseRightButtonDown -= OnMouseRightButtonDownIncrementValue; + } + } + } + + private static void OnMouseRightButtonDownIncrementValue(object sender, MouseButtonEventArgs e) { + var text_box = sender as TextBox; + if (text_box == null || String.IsNullOrWhiteSpace(text_box.Text)) { + return; + } else { + uint val = uint.Parse(text_box.Text); + if (val < uint.MaxValue) { + val++; + text_box.Text = val.ToString(); + } + } + } + + private static void OnMouseLeftButtonDownDecrementValue(object sender, MouseButtonEventArgs e) { + var text_box = sender as TextBox; + if (text_box == null || String.IsNullOrWhiteSpace(text_box.Text)) { + return; + } + else { + uint val = uint.Parse(text_box.Text); + if (val > uint.MinValue) { + val--; + text_box.Text = val.ToString(); + } + } + } + #endregion } } \ No newline at end of file diff --git a/src/client/spark/view/Spark/Ladder/LadderView.xaml b/src/client/spark/view/Spark/Ladder/LadderView.xaml index 310f800a8..6e6a6ca6c 100644 --- a/src/client/spark/view/Spark/Ladder/LadderView.xaml +++ b/src/client/spark/view/Spark/Ladder/LadderView.xaml @@ -339,9 +339,11 @@ />