forked from CommunityToolkit/WindowsCommunityToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed issue where narrator wasn't announcing progress changes for Ran…
…geSelector (Fixes CommunityToolkit#3538)
- Loading branch information
1 parent
62c4934
commit 1784fc8
Showing
5 changed files
with
181 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
Microsoft.Toolkit.Uwp.UI.Controls.Input/RangeSelector/RangeThumb.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Microsoft.Toolkit.Uwp.UI.Controls.Input/RangeSelector/RangeThumbAutomationPeer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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 class that provides a Microsoft UI Automation peer implementation for <see cref="RangeThumb"/>. | ||
/// </summary> | ||
public class RangeThumbAutomationPeer : RangeBaseAutomationPeer | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="RangeThumbAutomationPeer"/> class. | ||
/// </summary> | ||
/// <param name="owner">The owner element to create for.</param> | ||
public RangeThumbAutomationPeer(RangeThumb owner) | ||
: base(owner) | ||
{ | ||
} | ||
|
||
/// <inheritdoc/> | ||
protected override AutomationControlType GetAutomationControlTypeCore() => AutomationControlType.Slider; | ||
|
||
/// <inheritdoc/> | ||
protected override string GetClassNameCore() | ||
{ | ||
return nameof(RangeThumb); | ||
} | ||
} | ||
} |