This repository was archived by the owner on Feb 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathRangeSelector.Input.Drag.cs
More file actions
116 lines (93 loc) · 3.92 KB
/
RangeSelector.Input.Drag.cs
File metadata and controls
116 lines (93 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System;
using Windows.Foundation;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// RangeSelector is a "double slider" control for range values.
/// </summary>
public partial class RangeSelector : Control
{
private void MinThumb_DragDelta(object sender, DragDeltaEventArgs e)
{
_absolutePosition += e.HorizontalChange;
RangeStart = DragThumb(_minThumb, 0, DragWidth(), _absolutePosition);
if (_toolTipText != null)
{
UpdateToolTipText(this, _toolTipText, RangeStart);
}
}
private void MaxThumb_DragDelta(object sender, DragDeltaEventArgs e)
{
_absolutePosition += e.HorizontalChange;
RangeEnd = DragThumb(_maxThumb, 0, DragWidth(), _absolutePosition);
if (_toolTipText != null)
{
UpdateToolTipText(this, _toolTipText, RangeEnd);
}
}
private void MinThumb_DragStarted(object sender, DragStartedEventArgs e)
{
OnThumbDragStarted(e);
Thumb_DragStarted(_minThumb);
}
private void MaxThumb_DragStarted(object sender, DragStartedEventArgs e)
{
OnThumbDragStarted(e);
Thumb_DragStarted(_maxThumb);
}
private void Thumb_DragCompleted(object sender, DragCompletedEventArgs e)
{
OnThumbDragCompleted(e);
OnValueChanged(sender.Equals(_minThumb) ? new RangeChangedEventArgs(_oldValue, RangeStart, RangeSelectorProperty.MinimumValue) : new RangeChangedEventArgs(_oldValue, RangeEnd, RangeSelectorProperty.MaximumValue));
SyncThumbs();
if (_toolTip != null)
{
_toolTip.Visibility = Visibility.Collapsed;
}
VisualStateManager.GoToState(this, "Normal", true);
}
private double DragWidth()
{
return _containerCanvas.ActualWidth - _maxThumb.Width;
}
private double DragThumb(RangeThumb thumb, double min, double max, double nextPos)
{
nextPos = Math.Max(min, nextPos);
nextPos = Math.Min(max, nextPos);
Canvas.SetLeft(thumb, nextPos);
if (_toolTipText != null && _toolTip != null)
{
var thumbCenter = nextPos + (thumb.Width / 2);
_toolTip.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
var ttWidth = _toolTip.ActualWidth / 2;
Canvas.SetLeft(_toolTip, thumbCenter - ttWidth);
}
return Minimum + ((nextPos / DragWidth()) * (Maximum - Minimum));
}
private void Thumb_DragStarted(RangeThumb thumb)
{
var useMin = thumb == _minThumb;
var otherThumb = useMin ? _maxThumb : _minThumb;
_absolutePosition = Canvas.GetLeft(thumb);
Canvas.SetZIndex(thumb, 10);
Canvas.SetZIndex(otherThumb, 0);
_oldValue = RangeStart;
if (_toolTipText != null && _toolTip != null)
{
_toolTip.Visibility = Visibility.Visible;
var thumbCenter = _absolutePosition + (thumb.Width / 2);
_toolTip.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
var ttWidth = _toolTip.ActualWidth / 2;
Canvas.SetLeft(_toolTip, thumbCenter - ttWidth);
UpdateToolTipText(this, _toolTipText, useMin ? RangeStart : RangeEnd);
}
VisualStateManager.GoToState(this, useMin ? "MinPressed" : "MaxPressed", true);
}
}
}