Skip to content

Commit

Permalink
Merge branch 'master' into sample-app-updates
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-hawker authored Mar 11, 2021
2 parents a022a85 + 1c7e0e4 commit a3f4ce4
Show file tree
Hide file tree
Showing 14 changed files with 129 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Automation;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -45,7 +46,7 @@ private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChan
}
}

private DispatcherTimer updateTimer;
private DispatcherQueueTimer updateTimer;
private TextBlock controlName;
private TextBlock controlType;
private TextBlock controlAutomationName;
Expand All @@ -72,7 +73,7 @@ private void Start()
{
if (updateTimer == null)
{
updateTimer = new DispatcherTimer();
updateTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
updateTimer.Tick += UpdateTimer_Tick;
}

Expand Down
5 changes: 3 additions & 2 deletions Microsoft.Toolkit.Uwp.Input.GazeInteraction/GazePointer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Windows.Devices.Input.Preview;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.System;
using Windows.UI;
using Windows.UI.Core;
using Windows.UI.Xaml;
Expand Down Expand Up @@ -354,7 +355,7 @@ private GazePointer()
_gazeCursor = new GazeCursor();

// timer that gets called back if there gaze samples haven't been received in a while
_eyesOffTimer = new DispatcherTimer();
_eyesOffTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
_eyesOffTimer.Tick += OnEyesOff;

// provide a default of GAZE_IDLE_TIME microseconds to fire eyes off
Expand Down Expand Up @@ -860,7 +861,7 @@ private void OnDeviceRemoved(GazeDeviceWatcherPreview sender, GazeDeviceWatcherR

private readonly List<int> _roots = new List<int>();

private readonly DispatcherTimer _eyesOffTimer;
private readonly DispatcherQueueTimer _eyesOffTimer;

private readonly GazeCursor _gazeCursor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Animation;
Expand Down Expand Up @@ -149,17 +150,19 @@ void LoadedHandler(object s, RoutedEventArgs args)
listAnimProperty.ListViewBase.ScrollIntoView(parameter);

// give time to the UI thread to scroll the list
var t = listAnimProperty.ListViewBase.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
{
try
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
var t = dispatcherQueue.EnqueueAsync(
async () =>
{
var success = await listAnimProperty.ListViewBase.TryStartConnectedAnimationAsync(connectedAnimation, parameter, listAnimProperty.ElementName);
}
catch (Exception)
{
connectedAnimation.Cancel();
}
});
try
{
var success = await listAnimProperty.ListViewBase.TryStartConnectedAnimationAsync(connectedAnimation, parameter, listAnimProperty.ElementName);
}
catch (Exception)
{
connectedAnimation.Cancel();
}
}, DispatcherQueuePriority.Normal);

animationHandled = true;
}
Expand Down
9 changes: 4 additions & 5 deletions Microsoft.Toolkit.Uwp.UI.Behaviors/Focus/FocusBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Markup;
Expand Down Expand Up @@ -39,7 +40,7 @@ public sealed class FocusBehavior : BehaviorBase<UIElement>
typeof(FocusBehavior),
new PropertyMetadata(TimeSpan.FromMilliseconds(100)));

private DispatcherTimer _timer;
private DispatcherQueueTimer _timer;

/// <summary>
/// Initializes a new instance of the <see cref="FocusBehavior"/> class.
Expand Down Expand Up @@ -120,10 +121,8 @@ private void ApplyFocus()
// This allows us to handle the case where the controls are not loaded in the order we expect.
if (_timer is null)
{
_timer = new DispatcherTimer
{
Interval = FocusEngagementTimeout,
};
_timer = DispatcherQueue.GetForCurrentThread().CreateTimer();
_timer.Interval = FocusEngagementTimeout;
_timer.Tick += OnEngagementTimerTick;
_timer.Start();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Collections;
using System.Collections.Specialized;
using Microsoft.Toolkit.Uwp.Helpers;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media;
Expand All @@ -32,7 +33,7 @@ public partial class RotatorTile : Control

private static readonly Random Randomizer = new Random();
private int _currentIndex = -1; // current index in the items displayed
private DispatcherTimer _timer; // timer for triggering when to flip the content
private DispatcherQueueTimer _timer; // timer for triggering when to flip the content
private FrameworkElement _currentElement; // FrameworkElement holding a reference to the current element being display
private FrameworkElement _nextElement; // FrameworkElement holding a reference to the next element being display
private FrameworkElement _scroller; // Container Element that's being translated to animate from one item to the next
Expand Down Expand Up @@ -387,7 +388,8 @@ private void Start()

if (_timer == null)
{
_timer = new DispatcherTimer() { Interval = GetTileDuration() };
_timer = DispatcherQueue.GetForCurrentThread().CreateTimer();
_timer.Interval = GetTileDuration();
_timer.Tick += Timer_Tick;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.System;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -39,7 +40,7 @@ public partial class TileControl : ContentControl

private Size _imageSize = Size.Empty;

private DispatcherTimer _timerAnimation;
private DispatcherQueueTimer _timerAnimation;

/// <summary>
/// A ScrollViewer used for synchronized the move of the <see cref="TileControl"/>
Expand Down Expand Up @@ -609,7 +610,7 @@ private void InitializeAnimation()
{
if (_timerAnimation == null)
{
_timerAnimation = new DispatcherTimer();
_timerAnimation = DispatcherQueue.GetForCurrentThread().CreateTimer();
}
else
{
Expand Down
14 changes: 8 additions & 6 deletions Microsoft.Toolkit.Uwp.UI.Controls.DataGrid/DataGrid/DataGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private enum ScrollBarsSeparatorVisualState
private DataGridRow _focusedRow;
private FrameworkElement _frozenColumnScrollBarSpacer;
private bool _hasNoIndicatorStateStoryboardCompletedHandler;
private DispatcherTimer _hideScrollBarsTimer;
private DispatcherQueueTimer _hideScrollBarsTimer;

// the sum of the widths in pixels of the scrolling columns preceding
// the first displayed scrolling column
Expand Down Expand Up @@ -6423,19 +6423,19 @@ private void HideScrollBarsAfterDelay()
{
if (!_keepScrollBarsShowing)
{
DispatcherTimer hideScrollBarsTimer = null;
DispatcherQueueTimer hideScrollBarsTimer = null;

if (_hideScrollBarsTimer != null)
{
hideScrollBarsTimer = _hideScrollBarsTimer;
if (hideScrollBarsTimer.IsEnabled)
if (hideScrollBarsTimer.IsRunning)
{
hideScrollBarsTimer.Stop();
}
}
else
{
hideScrollBarsTimer = new DispatcherTimer();
hideScrollBarsTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
hideScrollBarsTimer.Interval = TimeSpan.FromMilliseconds(DATAGRID_noScrollBarCountdownMs);
hideScrollBarsTimer.Tick += HideScrollBarsTimerTick;
_hideScrollBarsTimer = hideScrollBarsTimer;
Expand Down Expand Up @@ -7958,6 +7958,7 @@ private void ResetValidationStatus()
int editingRowSlot = this.EditingRow.Slot;

InvalidateMeasure();
// TODO: Move to DispatcherQueue when FEATURE_VALIDATION_SUMMARY is enabled
this.Dispatcher.BeginInvoke(() =>
{
// It's possible that the DataContext or ItemsSource has changed by the time we reach this code,
Expand Down Expand Up @@ -8207,7 +8208,7 @@ private void ShowScrollBars()
}
else
{
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsEnabled)
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsRunning)
{
_hideScrollBarsTimer.Stop();
_hideScrollBarsTimer.Start();
Expand Down Expand Up @@ -8289,7 +8290,7 @@ private void ShowScrollBars()

private void StopHideScrollBarsTimer()
{
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsEnabled)
if (_hideScrollBarsTimer != null && _hideScrollBarsTimer.IsRunning)
{
_hideScrollBarsTimer.Stop();
}
Expand Down Expand Up @@ -8762,6 +8763,7 @@ private void UpdateValidationResults(List<ValidationResult> newValidationResults
// If the number of errors has changed, then the ValidationSummary will be a different size,
// and we need to delay our call to ScrollSlotIntoView
this.InvalidateMeasure();
// TODO: Move to DispatcherQueue when FEATURE_VALIDATION_SUMMARY is enabled
this.Dispatcher.BeginInvoke(() =>
{
// It's possible that the DataContext or ItemsSource has changed by the time we reach this code,
Expand Down
27 changes: 13 additions & 14 deletions Microsoft.Toolkit.Uwp.UI.Controls.Input/ColorPicker/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Globalization;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.UI.Controls.ColorPickerConverters;
using Windows.System;
using Windows.UI;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
Expand Down Expand Up @@ -74,7 +75,7 @@ public partial class ColorPicker : Windows.UI.Xaml.Controls.ColorPicker
private HsvColor? savedHsvColor = null;
private Color? savedHsvColorRgbEquivalent = null;
private Color? updatedRgbColor = null;
private DispatcherTimer dispatcherTimer = null;
private DispatcherQueueTimer dispatcherQueueTimer = null;

private ColorSpectrum ColorSpectrumControl;
private ColorPickerSlider ColorSpectrumAlphaSlider;
Expand Down Expand Up @@ -134,15 +135,15 @@ public ColorPicker()

this.ConnectCallbacks(true);
this.SetDefaultPalette();
this.StartDispatcherTimer();
this.StartDispatcherQueueTimer();
}

/// <summary>
/// Finalizes an instance of the <see cref="ColorPicker"/> class.
/// </summary>
~ColorPicker()
{
this.StopDispatcherTimer();
this.StopDispatcherQueueTimer();
this.CustomPaletteColors.CollectionChanged -= CustomPaletteColors_CollectionChanged;
}

Expand Down Expand Up @@ -1068,29 +1069,27 @@ private void SetDefaultPalette()
*
***************************************************************************************/

private void StartDispatcherTimer()
private void StartDispatcherQueueTimer()
{
this.dispatcherTimer = new DispatcherTimer()
{
Interval = new TimeSpan(0, 0, 0, 0, ColorUpdateInterval)
};
this.dispatcherTimer.Tick += DispatcherTimer_Tick;
this.dispatcherTimer.Start();
this.dispatcherQueueTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
this.dispatcherQueueTimer.Interval = new TimeSpan(0, 0, 0, 0, ColorUpdateInterval);
this.dispatcherQueueTimer.Tick += DispatcherQueueTimer_Tick;
this.dispatcherQueueTimer.Start();

return;
}

private void StopDispatcherTimer()
private void StopDispatcherQueueTimer()
{
if (this.dispatcherTimer != null)
if (this.dispatcherQueueTimer != null)
{
this.dispatcherTimer.Stop();
this.dispatcherQueueTimer.Stop();
}

return;
}

private void DispatcherTimer_Tick(object sender, object e)
private void DispatcherQueueTimer_Tick(object sender, object e)
{
if (this.updatedRgbColor != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.DataTransfer;
using Windows.UI.Core;
using Windows.System;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Input;
Expand Down Expand Up @@ -136,28 +136,30 @@ private TokenizingTextBoxItem GetCurrentContainerItem()

internal void SelectAllTokensAndText()
{
_ = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
this.SelectAllSafe();
var dispatcherQueue = DispatcherQueue.GetForCurrentThread();
_ = dispatcherQueue.EnqueueAsync(
() =>
{
this.SelectAllSafe();

// need to synchronize the select all and the focus behavior on the text box
// because there is no way to identify that the focus has been set from this point
// to avoid instantly clearing the selection of tokens
PauseTokenClearOnFocus = true;
// need to synchronize the select all and the focus behavior on the text box
// because there is no way to identify that the focus has been set from this point
// to avoid instantly clearing the selection of tokens
PauseTokenClearOnFocus = true;

foreach (var item in Items)
{
if (item is ITokenStringContainer)
foreach (var item in Items)
{
// grab any selected text
var pretoken = ContainerFromItem(item) as TokenizingTextBoxItem;
pretoken._autoSuggestTextBox.SelectionStart = 0;
pretoken._autoSuggestTextBox.SelectionLength = pretoken._autoSuggestTextBox.Text.Length;
if (item is ITokenStringContainer)
{
// grab any selected text
var pretoken = ContainerFromItem(item) as TokenizingTextBoxItem;
pretoken._autoSuggestTextBox.SelectionStart = 0;
pretoken._autoSuggestTextBox.SelectionLength = pretoken._autoSuggestTextBox.Text.Length;
}
}
}

(ContainerFromIndex(Items.Count - 1) as TokenizingTextBoxItem).Focus(FocusState.Programmatic);
});
(ContainerFromIndex(Items.Count - 1) as TokenizingTextBoxItem).Focus(FocusState.Programmatic);
}, DispatcherQueuePriority.Normal);
}

internal void DeselectAllTokensAndText(TokenizingTextBoxItem ignoreItem = null)
Expand Down
Loading

0 comments on commit a3f4ce4

Please sign in to comment.