Merge branch 'master' into wrap-panel-tests

This commit is contained in:
Kyaa Dost 2021-03-25 14:09:55 -07:00 коммит произвёл GitHub
Родитель 4f25bf1163 ce535519fb
Коммит 6347f1027b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 54 добавлений и 40 удалений

Просмотреть файл

@ -34,19 +34,19 @@ namespace Microsoft.Toolkit.Uwp.DeveloperTools
private static void OnIsActiveChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var focusTracker = d as FocusTracker;
if (e.NewValue != null && (bool)e.NewValue)
if (d is FocusTracker focusTracker)
{
focusTracker?.Start();
}
else
{
focusTracker?.Stop();
if (e.NewValue != null && (bool)e.NewValue)
{
focusTracker.Start();
}
else
{
focusTracker.Stop();
}
}
}
private DispatcherQueueTimer updateTimer;
private TextBlock controlName;
private TextBlock controlType;
private TextBlock controlAutomationName;
@ -69,23 +69,6 @@ namespace Microsoft.Toolkit.Uwp.DeveloperTools
DefaultStyleKey = typeof(FocusTracker);
}
private void Start()
{
if (updateTimer == null)
{
updateTimer = DispatcherQueue.GetForCurrentThread().CreateTimer();
updateTimer.Tick += UpdateTimer_Tick;
}
updateTimer.Start();
}
private void Stop()
{
updateTimer?.Stop();
ClearContent();
}
/// <summary>
/// Update the visual state of the control when its template is changed.
/// </summary>
@ -97,6 +80,33 @@ namespace Microsoft.Toolkit.Uwp.DeveloperTools
controlFirstParentWithName = GetTemplateChild("ControlFirstParentWithName") as TextBlock;
}
private void Start()
{
// Get currently focused control once when we start
if (Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "XamlRoot") && XamlRoot != null)
{
FocusOnControl(FocusManager.GetFocusedElement(XamlRoot) as FrameworkElement);
}
else
{
FocusOnControl(FocusManager.GetFocusedElement() as FrameworkElement);
}
// Then use FocusManager event from 1809 to listen to updates
FocusManager.GotFocus += FocusManager_GotFocus;
}
private void Stop()
{
FocusManager.GotFocus -= FocusManager_GotFocus;
ClearContent();
}
private void FocusManager_GotFocus(object sender, FocusManagerGotFocusEventArgs e)
{
FocusOnControl(e.NewFocusedElement as FrameworkElement);
}
private void ClearContent()
{
controlName.Text = string.Empty;
@ -105,19 +115,8 @@ namespace Microsoft.Toolkit.Uwp.DeveloperTools
controlFirstParentWithName.Text = string.Empty;
}
private void UpdateTimer_Tick(object sender, object e)
private void FocusOnControl(FrameworkElement focusedControl)
{
FrameworkElement focusedControl;
if (Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent("Windows.UI.Xaml.UIElement", "XamlRoot") && XamlRoot != null)
{
focusedControl = FocusManager.GetFocusedElement(XamlRoot) as FrameworkElement;
}
else
{
focusedControl = FocusManager.GetFocusedElement() as FrameworkElement;
}
if (focusedControl == null)
{
ClearContent();

Просмотреть файл

@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.
using System;
using System.Threading.Tasks;
using Microsoft.Toolkit.Uwp.Helpers;
using Microsoft.Toolkit.Uwp.SampleApp.Common;
using Microsoft.Toolkit.Uwp.SampleApp.SamplePages;
@ -163,7 +164,7 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
private async void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
@ -179,7 +180,18 @@ namespace Microsoft.Toolkit.Uwp.SampleApp
// ignore
}
deferral.Complete();
try
{
await Task.Delay(2000);
}
catch
{
// ignore
}
finally
{
deferral.Complete();
}
}
}
}

Просмотреть файл

@ -27,5 +27,8 @@
<!-- Add your application specific runtime directives here. -->
<Type Name="Windows.UI.Xaml.Controls.Border" Dynamic="Required Public" />
<!-- Fix for https://github.com/windows-toolkit/WindowsCommunityToolkit/issues/3883 -->
<Type Name="Windows.UI.Xaml.Controls.TextBlock" Dynamic="Required Public" />
</Application>
</Directives>