框架导航和应用工具条

本文关键字:工具 应用 导航 框架 | 更新日期: 2023-09-27 17:49:36

我正在尝试实现自定义导航系统的WinRT(特别是- Windows Phone 8.1)。而不是通常的页面导航,我想创建一个HostPage,它将包括一个单一的框架。我将把每个页面变成UserControl和导航服务将HostPage的帧设置为UserControl的缓存实例。我工作得很好,但我有一个问题与BottomAppBar。我不知道如何在UserControl中定义CommandBar并将其绑定到HostPage。什么好主意吗?

框架导航和应用工具条

一个可能的解决方案:

将其内容定义为UserControl的资源中的DataTemplate(使用公共键)。然后在HostPage中,你可以从UserControl中获得它。资源[YourCommonKey],并将其设置为命令栏的内容。

使用这个方法来加载DataTemplate的内容:https://msdn.microsoft.com/en-us/library/system.windows.frameworktemplate.loadcontent%28v=vs.110%29.aspx

不要使用xaml来创建Page.BottomAppBar。用途:

CommandBar bar = new CommandBar();
AppBarButton appBarButton = new AppBarButton();
BitmapIcon bi = new BitmapIcon();
bi.UriSource = item.Uri;
appBarButton.Icon = bi;
appBarButton.Label = item.Text;
appBarButton.Click += (sender, e) => item.Action();
yourPageRef.BottomAppBar = bar;
ApplicationBar.PrimaryCommands.Add(appBarButton);

那么你可以在任何你喜欢的地方保存引用。这个想法是只有一个命令栏,你可以根据UserControl来清除和添加按钮。