Skip to content

Commit 8a556b6

Browse files
committed
Implementing #7
Incrementing/Decrementing via mouse can be configured to: - Vertical only - Horizontal only - Vertical and Horizontal mouse drags.
1 parent 869afbe commit 8a556b6

File tree

3 files changed

+49
-3
lines changed

3 files changed

+49
-3
lines changed

source/NumericUpDownLib/Base/AbstractBaseUpDown.xaml.cs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
namespace NumericUpDownLib.Base
22
{
3+
using NumericUpDownLib.Enums;
34
using NumericUpDownLib.Models;
45
using System;
56
using System.Windows;
@@ -165,6 +166,13 @@ public abstract partial class AbstractBaseUpDown<T> : InputBaseUpDown
165166
DependencyProperty.Register("IsMouseDragEnabled", typeof(bool),
166167
typeof(AbstractBaseUpDown<T>), new PropertyMetadata(true, OnIsMouseDragEnabledChanged));
167168

169+
/// <summary>
170+
/// Backing store of <see cref="CanIncDecMouseDrag"/> dependency property.
171+
/// </summary>
172+
public static readonly DependencyProperty CanMouseDragProperty =
173+
DependencyProperty.Register("CanMouseDrag", typeof(CanIncDecMouseDrag),
174+
typeof(AbstractBaseUpDown<T>), new PropertyMetadata(CanIncDecMouseDrag.VerticalHorizontal));
175+
168176
/// <summary>
169177
/// Holds the REQUIRED textbox instance part for this control.
170178
/// </summary>
@@ -353,6 +361,18 @@ public bool IsMouseDragEnabled
353361
set { SetValue(IsMouseDragEnabledProperty, value); }
354362
}
355363

364+
/// <summary>
365+
/// Gets/sets wether small/large step sizes can be incremented/decremented
366+
/// both with vertical/horizontal mouse drag moves or,
367+
/// whether only horizontal or only vertical mouse drag moves can
368+
/// incremented/decremented only in small or only in large values.
369+
/// </summary>
370+
public CanIncDecMouseDrag CanMouseDrag
371+
{
372+
get { return (CanIncDecMouseDrag)GetValue(CanMouseDragProperty); }
373+
set { SetValue(CanMouseDragProperty, value); }
374+
}
375+
356376
/// <summary>
357377
/// Determines whether last text input was from a user (key was down) or not.
358378
/// </summary>
@@ -594,8 +614,8 @@ private void _PART_TextBox_MouseMove(object sender, MouseEventArgs e)
594614
}
595615

596616
var pos = GetPositionFromThis(e);
597-
double deltaX = _objMouseIncr.Point.X - pos.X;
598-
double deltaY = _objMouseIncr.Point.Y - pos.Y;
617+
double deltaX = (CanMouseDrag == CanIncDecMouseDrag.VerticalOnly ? 0 : _objMouseIncr.Point.X - pos.X);
618+
double deltaY = (CanMouseDrag == CanIncDecMouseDrag.HorizontalOnly ? 0 : _objMouseIncr.Point.Y - pos.Y);
599619

600620
if (_objMouseIncr.MouseDirection == MouseDirections.None)
601621
{
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace NumericUpDownLib.Enums
2+
{
3+
/// <summary>
4+
/// Defines the mouse drag modes that are supported to increment/decrement
5+
/// small/large values allowing horizontal/vertical mouse drag moves at the same
6+
/// time or each direction only by itself.
7+
/// </summary>
8+
public enum CanIncDecMouseDrag
9+
{
10+
/// <summary>
11+
/// A value can be incremented/decremented in small steps using vertical mouse drag moves only.
12+
/// </summary>
13+
VerticalOnly,
14+
15+
/// <summary>
16+
/// A value can be incremented/decremented in large steps using horizontal mouse drag moves only.
17+
/// </summary>
18+
HorizontalOnly,
19+
20+
/// <summary>
21+
/// A value can be incremented/decremented in small steps or large steps
22+
/// using vertical or horizontal mouse drag moves at the same time.
23+
/// </summary>
24+
VerticalHorizontal
25+
}
26+
}

source/NumericUpDownLib/NumericUpDownLib.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
</PropertyGroup>
2525

2626
<ItemGroup>
27-
<None Include="images/SyncArrow_64x.png" Pack="true" PackagePath=""/>
27+
<None Include="images/SyncArrow_64x.png" Pack="true" PackagePath="" />
2828
</ItemGroup>
2929

3030
<ItemGroup>

0 commit comments

Comments
 (0)