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 pathRangeThumb.cs
More file actions
78 lines (62 loc) · 2.42 KB
/
RangeThumb.cs
File metadata and controls
78 lines (62 loc) · 2.42 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
// 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.UI.Xaml;
using Windows.UI.Xaml.Automation.Peers;
using Windows.UI.Xaml.Controls.Primitives;
namespace Microsoft.Toolkit.Uwp.UI.Controls
{
/// <summary>
/// A thumb that represents a value within a range.
/// </summary>
[TemplatePart(Name = "InternalThumb", Type = typeof(Thumb))]
public class RangeThumb : RangeBase
{
private Thumb _thumb;
/// <inheritdoc cref="Thumb.DragStarted"/>
public event EventHandler<DragStartedEventArgs> DragStarted;
/// <inheritdoc cref="Thumb.DragCompleted"/>
public event EventHandler<DragCompletedEventArgs> DragCompleted;
/// <inheritdoc cref="Thumb.DragDelta"/>
public event EventHandler<DragDeltaEventArgs> DragDelta;
/// <inheritdoc/>
protected override void OnApplyTemplate()
{
_thumb = GetTemplateChild("InternalThumb") as Thumb;
if (_thumb is not null)
{
AttachEvents(_thumb);
}
Unloaded += RangeThumb_Unloaded;
base.OnApplyTemplate();
}
private void AttachEvents(Thumb thumb)
{
thumb.DragCompleted += Thumb_DragCompleted;
thumb.DragStarted += Thumb_DragStarted;
thumb.DragDelta += Thumb_DragDelta;
}
private void DetachEvents(Thumb thumb)
{
thumb.DragCompleted -= Thumb_DragCompleted;
thumb.DragStarted -= Thumb_DragStarted;
thumb.DragDelta -= Thumb_DragDelta;
}
private void Thumb_DragStarted(object sender, DragStartedEventArgs e) => DragStarted?.Invoke(this, e);
private void Thumb_DragDelta(object sender, DragDeltaEventArgs e) => DragDelta?.Invoke(this, e);
private void Thumb_DragCompleted(object sender, DragCompletedEventArgs e) => DragCompleted?.Invoke(this, e);
private void RangeThumb_Unloaded(object sender, RoutedEventArgs e)
{
if (_thumb is not null)
{
DetachEvents(_thumb);
}
}
/// <inheritdoc/>
protected override AutomationPeer OnCreateAutomationPeer()
{
return new RangeThumbAutomationPeer(this);
}
}
}