master
cs 23 lines 975 Bytes
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2
3 using Microsoft.UI.Xaml;
4 using Microsoft.UI.Xaml.Controls;
5
6 namespace WslSettings.Helpers;
7
8 // Helper class to set the navigation target for a NavigationViewItem.
9 //
10 // Usage in XAML:
11 // <NavigationViewItem x:Uid="Shell_Main" Icon="Document" helpers:NavigationHelper.NavigateTo="AppName.ViewModels.MainViewModel" />
12 //
13 // Usage in code:
14 // NavigationHelper.SetNavigateTo(navigationViewItem, typeof(MainViewModel).FullName);
15 public class NavigationHelper
16 {
17 public static string GetNavigateTo(NavigationViewItem item) => (string)item.GetValue(NavigateToProperty);
18
19 public static void SetNavigateTo(NavigationViewItem item, string value) => item.SetValue(NavigateToProperty, value);
20
21 public static readonly DependencyProperty NavigateToProperty =
22 DependencyProperty.RegisterAttached("NavigateTo", typeof(string), typeof(NavigationHelper), new PropertyMetadata(null));
23 }