mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-03 17:56:44 +02:00
## Summary of the Pull Request This change upgrades the WinUIEx NuGet package from version 2.2.0 to 2.8.0. - Prevents the window itself from taking focus when it should not. - Removes dead code from Settings.UI (the code triggered error [WinUIEX1001](https://dotmorten.github.io/WinUIEx/rules/WinUIEx1001.html) -- Window.Current is always null). ## PR Checklist - [x] Closes: #40637 - [x] Closes: #7647 - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed I've built and run [projects utilizing WinUIEx](https://github.com/search?q=repo%3Amicrosoft%2FPowerToys+WinUIEx+path%3A*.*proj&type=code): - Microsoft.CmdPal.UI - MeasureToolUI - FileLocksmithUI - EnvironmentVariables - AdvancedPaste - Peek.UI - RegistryPreview - PowerToys.Settings - Hosts
109 lines
3.1 KiB
C#
109 lines
3.1 KiB
C#
// Copyright (c) Microsoft Corporation
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
using System;
|
|
|
|
using Microsoft.UI.Xaml;
|
|
using Microsoft.UI.Xaml.Controls;
|
|
using Microsoft.UI.Xaml.Media.Animation;
|
|
using Microsoft.UI.Xaml.Navigation;
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Services
|
|
{
|
|
public static class NavigationService
|
|
{
|
|
public static event NavigatedEventHandler Navigated;
|
|
|
|
public static event NavigationFailedEventHandler NavigationFailed;
|
|
|
|
private static Frame frame;
|
|
private static object lastParamUsed;
|
|
|
|
public static Frame Frame
|
|
{
|
|
get
|
|
{
|
|
return frame;
|
|
}
|
|
|
|
set
|
|
{
|
|
UnregisterFrameEvents();
|
|
frame = value;
|
|
RegisterFrameEvents();
|
|
}
|
|
}
|
|
|
|
public static bool CanGoBack => Frame.CanGoBack;
|
|
|
|
public static bool CanGoForward => Frame.CanGoForward;
|
|
|
|
public static bool GoBack()
|
|
{
|
|
if (CanGoBack)
|
|
{
|
|
Frame.GoBack();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public static void GoForward() => Frame.GoForward();
|
|
|
|
public static bool Navigate(Type pageType, object parameter = null, NavigationTransitionInfo infoOverride = null)
|
|
{
|
|
// Don't open the same page multiple times
|
|
if (Frame.Content?.GetType() != pageType || (parameter != null && !parameter.Equals(lastParamUsed)))
|
|
{
|
|
var navigationResult = Frame.Navigate(pageType, parameter, infoOverride);
|
|
if (navigationResult)
|
|
{
|
|
lastParamUsed = parameter;
|
|
}
|
|
|
|
return navigationResult;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static bool Navigate<T>(object parameter = null, NavigationTransitionInfo infoOverride = null)
|
|
where T : Page
|
|
=> Navigate(typeof(T), parameter, infoOverride);
|
|
|
|
private static void RegisterFrameEvents()
|
|
{
|
|
if (frame != null)
|
|
{
|
|
frame.Navigated += Frame_Navigated;
|
|
frame.NavigationFailed += Frame_NavigationFailed;
|
|
}
|
|
}
|
|
|
|
private static void UnregisterFrameEvents()
|
|
{
|
|
if (frame != null)
|
|
{
|
|
frame.Navigated -= Frame_Navigated;
|
|
frame.NavigationFailed -= Frame_NavigationFailed;
|
|
}
|
|
}
|
|
|
|
private static void Frame_NavigationFailed(object sender, NavigationFailedEventArgs e) => NavigationFailed?.Invoke(sender, e);
|
|
|
|
private static void Frame_Navigated(object sender, NavigationEventArgs e) => Navigated?.Invoke(sender, e);
|
|
|
|
internal static void EnsurePageIsSelected(Type pageType)
|
|
{
|
|
if (Frame.Content == null)
|
|
{
|
|
Frame.Navigate(pageType);
|
|
}
|
|
}
|
|
}
|
|
}
|