Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System;
using Microsoft.Toolkit.Uwp.UI.Extensions;
using Windows.Foundation;
using Windows.System;
using Windows.UI.Xaml;
Expand Down Expand Up @@ -35,6 +36,7 @@ public partial class RangeSelector : Control
private const double DefaultMinimum = 0.0;
private const double DefaultMaximum = 1.0;
private const double DefaultStepFrequency = 1;
private static readonly TimeSpan TimeToHideToolTipOnKeyUp = TimeSpan.FromSeconds(1);

/// <summary>
/// Identifies the Minimum dependency property.
Expand All @@ -61,6 +63,8 @@ public partial class RangeSelector : Control
/// </summary>
public static readonly DependencyProperty StepFrequencyProperty = DependencyProperty.Register(nameof(StepFrequency), typeof(double), typeof(RangeSelector), new PropertyMetadata(DefaultStepFrequency));

private readonly DispatcherQueueTimer keyDebounceTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();

private Border _outOfRangeContentContainer;
private Rectangle _activeRectangle;
private Thumb _minThumb;
Expand Down Expand Up @@ -247,7 +251,9 @@ private void Thumb_KeyUp(object sender, KeyRoutedEventArgs e)
case VirtualKey.Right:
if (_toolTip != null)
{
_toolTip.Visibility = Visibility.Collapsed;
keyDebounceTimer.Debounce(
() => _toolTip.Visibility = Visibility.Collapsed,
TimeToHideToolTipOnKeyUp);
}

e.Handled = true;
Expand Down
15 changes: 0 additions & 15 deletions Microsoft.Toolkit.Uwp.UI.Controls/RangeSelector/RangeSelector.xaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:animations="using:Microsoft.Toolkit.Uwp.UI.Animations"
xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">

<Style x:Key="SliderThumbStyle"
Expand Down Expand Up @@ -58,20 +57,6 @@
BorderBrush="{ThemeResource SystemControlForegroundChromeHighBrush}"
BorderThickness="1"
Visibility="Collapsed">
<animations:Implicit.ShowAnimations>
<animations:OpacityAnimation From="0"
To="1.0"
Duration="0:0:0.3" />
</animations:Implicit.ShowAnimations>

<animations:Implicit.HideAnimations>
<animations:ScalarAnimation Target="Opacity"
To="0"
Duration="0:0:1">
<animations:ScalarKeyFrame Key="0.7"
Value="1.0" />
</animations:ScalarAnimation>
</animations:Implicit.HideAnimations>
<TextBlock x:Name="ToolTipText"
Margin="8"
Foreground="{ThemeResource SystemControlForegroundBaseHighBrush}" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

using System;
using System.Collections.Concurrent;
using Windows.UI.Xaml;
using Windows.System;

namespace Microsoft.Toolkit.Uwp.UI.Extensions
{
/// <summary>
/// Set of extention methods for using <see cref="DispatcherTimer"/>.
/// Set of extention methods for using <see cref="DispatcherQueueTimer"/>.
/// </summary>
public static class DispatcherTimerExtensions
public static class DispatcherQueueTimerExtensions
{
private static ConcurrentDictionary<DispatcherTimer, Action> _debounceInstances = new ConcurrentDictionary<DispatcherTimer, Action>();
private static ConcurrentDictionary<DispatcherQueueTimer, Action> _debounceInstances = new ConcurrentDictionary<DispatcherQueueTimer, Action>();

/// <summary>
/// <para>Used to debounce (rate-limit) an event. The action will be postponed and executed after the interval has elapsed. At the end of the interval, the function will be called with the arguments that were passed most recently to the debounced function.</para>
Expand All @@ -27,18 +27,18 @@ public static class DispatcherTimerExtensions
/// <param name="immediate">Determines if the action execute on the leading edge instead of trailing edge.</param>
/// <example>
/// <code>
/// private DispatcherTimer _typeTimer = new DispatcherTimer();
/// private DispatcherQueueTimer _typeTimer = new DispatcherQueueTimer();
///
/// _typeTimer.Debounce(async () =>
/// {
/// // Only executes this code after 0.3 seconds have elapsed since last trigger.
/// }, TimeSpan.FromSeconds(0.3));
/// </code>
/// </example>
public static void Debounce(this DispatcherTimer timer, Action action, TimeSpan interval, bool immediate = false)
public static void Debounce(this DispatcherQueueTimer timer, Action action, TimeSpan interval, bool immediate = false)
{
// Check and stop any existing timer
var timeout = timer.IsEnabled;
var timeout = timer.IsRunning;
if (timeout)
{
timer.Stop();
Expand Down Expand Up @@ -72,7 +72,7 @@ public static void Debounce(this DispatcherTimer timer, Action action, TimeSpan
private static void Timer_Tick(object sender, object e)
{
// This event is only registered/run if we weren't in immediate mode above
if (sender is DispatcherTimer timer)
if (sender is DispatcherQueueTimer timer)
{
timer.Tick -= Timer_Tick;
timer.Stop();
Expand Down