【发布时间】:2018-02-06 02:28:02
【问题描述】:
我正在将现有的 UWP 应用移植到 Template10。该应用程序将汉堡菜单实现为自定义外壳,它具有本地 Template10 汉堡菜单模板的所有功能,但也有很多特定于我的应用程序的功能,所以我不想使用库提供的模板和继续使用现有的 shell。
在 shell 中有一个名为 ContentFrame 的 Frame 对象,它应该处理所有页面导航。不知何故,我需要为框架获取一个 INavigationService 对象。在玩了一些之后(我没有找到任何关于使用自定义 shell 和 NavigationService 的综合文档)我得到了它,但我不完全确定为什么:
public override UIElement CreateRootElement(IActivatedEventArgs e)
{
_shell = new Shell();
NavigationServiceFactory(BackButton.Attach, ExistingContent.Exclude, _shell.ContentFrame);
return new ModalDialog
{
Content = _shell
};
}
public override async Task OnStartAsync(StartKind startKind, IActivatedEventArgs args)
{
var navService = _shell.ContentFrame.GetNavigationService();
navService?.NavigateAsync(typeof(TestPage));
}
如果我忽略NavigationServiceFactory() 的调用,代码将不起作用。那么,您是否应该在创建需要 NavigationService 的 Frame 时调用它?工厂是否创建某种全局 NavigationService,以后可以使用GetNavigationService() 定位。尽管我的代码似乎可以工作,但我希望在继续之前确认这一点。
【问题讨论】:
标签: uwp template10