NavHelper.cs
1 // Copyright (c) Microsoft Corporation 2 // The Microsoft Corporation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 using System; 6 7 using Microsoft.UI.Xaml; 8 using Microsoft.UI.Xaml.Controls; 9 10 namespace Microsoft.PowerToys.Settings.UI.Helpers 11 { 12 public static class NavHelper 13 { 14 // This helper class allows to specify the page that will be shown when you click on a NavigationViewItem 15 // 16 // Usage in xaml: 17 // <winui:NavigationViewItem x:Uid="Shell_Main" Icon="Document" helpers:NavHelper.NavigateTo="views:MainPage" /> 18 // 19 // Usage in code: 20 // NavHelper.SetNavigateTo(navigationViewItem, typeof(MainPage)); 21 public static Type GetNavigateTo(NavigationViewItem item) 22 { 23 return (Type)item?.GetValue(NavigateToProperty); 24 } 25 26 public static void SetNavigateTo(NavigationViewItem item, Type value) 27 { 28 item?.SetValue(NavigateToProperty, value); 29 } 30 31 public static readonly DependencyProperty NavigateToProperty = 32 DependencyProperty.RegisterAttached("NavigateTo", typeof(Type), typeof(NavHelper), new PropertyMetadata(null)); 33 } 34 }