mirror of
https://github.com/PacktPublishing/Learn-WinUI-3-Second-Edition.git
synced 2026-06-20 12:23:09 +00:00
Add chapter 10 sample project
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
|
||||
namespace TemplateStudioSampleApp.Helpers;
|
||||
|
||||
// Helper class to set the navigation target for a NavigationViewItem.
|
||||
//
|
||||
// Usage in XAML:
|
||||
// <NavigationViewItem x:Uid="Shell_Main" Icon="Document" helpers:NavigationHelper.NavigateTo="AppName.ViewModels.MainViewModel" />
|
||||
//
|
||||
// Usage in code:
|
||||
// NavigationHelper.SetNavigateTo(navigationViewItem, typeof(MainViewModel).FullName);
|
||||
public class NavigationHelper
|
||||
{
|
||||
public static string GetNavigateTo(NavigationViewItem item) => (string)item.GetValue(NavigateToProperty);
|
||||
|
||||
public static void SetNavigateTo(NavigationViewItem item, string value) => item.SetValue(NavigateToProperty, value);
|
||||
|
||||
public static readonly DependencyProperty NavigateToProperty =
|
||||
DependencyProperty.RegisterAttached("NavigateTo", typeof(string), typeof(NavigationHelper), new PropertyMetadata(null));
|
||||
}
|
||||
Reference in New Issue
Block a user