mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
* [Analyzers][Settings] Fix SA1516 * [Analyzers][Workspaces] Fix SA1516 * [Analyzers][Awake] Fix SA1516 * [Analyzers][Wox] Fix SA1516 * [MWB] Disable CA1716 warning on class name * [Wox] Update ExecuteFilePath property visibility for Json Source Generator * [Analyzers][MWB] Fix CA1716 on NativeMethods. --------- Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
115 lines
3.2 KiB
C#
115 lines
3.2 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
|
|
{
|
|
if (frame == null)
|
|
{
|
|
frame = Window.Current.Content as Frame;
|
|
RegisterFrameEvents();
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|