From 8a556b62e28b2d1645474abcdbbe26b1451dc3ab Mon Sep 17 00:00:00 2001 From: Dirkster99 Date: Mon, 4 May 2020 00:49:00 +0200 Subject: [PATCH] Implementing #7 Incrementing/Decrementing via mouse can be configured to: - Vertical only - Horizontal only - Vertical and Horizontal mouse drags. --- .../Base/AbstractBaseUpDown.xaml.cs | 24 +++++++++++++++-- .../Enums/CanIncDecMouseDrag.cs | 26 +++++++++++++++++++ .../NumericUpDownLib/NumericUpDownLib.csproj | 2 +- 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 source/NumericUpDownLib/Enums/CanIncDecMouseDrag.cs diff --git a/source/NumericUpDownLib/Base/AbstractBaseUpDown.xaml.cs b/source/NumericUpDownLib/Base/AbstractBaseUpDown.xaml.cs index f6c0897..c340c66 100644 --- a/source/NumericUpDownLib/Base/AbstractBaseUpDown.xaml.cs +++ b/source/NumericUpDownLib/Base/AbstractBaseUpDown.xaml.cs @@ -1,5 +1,6 @@ namespace NumericUpDownLib.Base { + using NumericUpDownLib.Enums; using NumericUpDownLib.Models; using System; using System.Windows; @@ -165,6 +166,13 @@ public abstract partial class AbstractBaseUpDown : InputBaseUpDown DependencyProperty.Register("IsMouseDragEnabled", typeof(bool), typeof(AbstractBaseUpDown), new PropertyMetadata(true, OnIsMouseDragEnabledChanged)); + /// + /// Backing store of dependency property. + /// + public static readonly DependencyProperty CanMouseDragProperty = + DependencyProperty.Register("CanMouseDrag", typeof(CanIncDecMouseDrag), + typeof(AbstractBaseUpDown), new PropertyMetadata(CanIncDecMouseDrag.VerticalHorizontal)); + /// /// Holds the REQUIRED textbox instance part for this control. /// @@ -353,6 +361,18 @@ public bool IsMouseDragEnabled set { SetValue(IsMouseDragEnabledProperty, value); } } + /// + /// Gets/sets wether small/large step sizes can be incremented/decremented + /// both with vertical/horizontal mouse drag moves or, + /// whether only horizontal or only vertical mouse drag moves can + /// incremented/decremented only in small or only in large values. + /// + public CanIncDecMouseDrag CanMouseDrag + { + get { return (CanIncDecMouseDrag)GetValue(CanMouseDragProperty); } + set { SetValue(CanMouseDragProperty, value); } + } + /// /// Determines whether last text input was from a user (key was down) or not. /// @@ -594,8 +614,8 @@ private void _PART_TextBox_MouseMove(object sender, MouseEventArgs e) } var pos = GetPositionFromThis(e); - double deltaX = _objMouseIncr.Point.X - pos.X; - double deltaY = _objMouseIncr.Point.Y - pos.Y; + double deltaX = (CanMouseDrag == CanIncDecMouseDrag.VerticalOnly ? 0 : _objMouseIncr.Point.X - pos.X); + double deltaY = (CanMouseDrag == CanIncDecMouseDrag.HorizontalOnly ? 0 : _objMouseIncr.Point.Y - pos.Y); if (_objMouseIncr.MouseDirection == MouseDirections.None) { diff --git a/source/NumericUpDownLib/Enums/CanIncDecMouseDrag.cs b/source/NumericUpDownLib/Enums/CanIncDecMouseDrag.cs new file mode 100644 index 0000000..2697a0d --- /dev/null +++ b/source/NumericUpDownLib/Enums/CanIncDecMouseDrag.cs @@ -0,0 +1,26 @@ +namespace NumericUpDownLib.Enums +{ + /// + /// Defines the mouse drag modes that are supported to increment/decrement + /// small/large values allowing horizontal/vertical mouse drag moves at the same + /// time or each direction only by itself. + /// + public enum CanIncDecMouseDrag + { + /// + /// A value can be incremented/decremented in small steps using vertical mouse drag moves only. + /// + VerticalOnly, + + /// + /// A value can be incremented/decremented in large steps using horizontal mouse drag moves only. + /// + HorizontalOnly, + + /// + /// A value can be incremented/decremented in small steps or large steps + /// using vertical or horizontal mouse drag moves at the same time. + /// + VerticalHorizontal + } +} diff --git a/source/NumericUpDownLib/NumericUpDownLib.csproj b/source/NumericUpDownLib/NumericUpDownLib.csproj index 517e795..20d5d4e 100644 --- a/source/NumericUpDownLib/NumericUpDownLib.csproj +++ b/source/NumericUpDownLib/NumericUpDownLib.csproj @@ -24,7 +24,7 @@ - +