在 Universal Windows App 的多个页面上使用 AppBar 作为资源

Use AppBar as resource on multiple pages in Universal Windows App

我想在多个页面上使用 AppBar 作为资源。 我找到了一份 MSDN 文档 (link),但它适用于 Windows Phone.

有谁知道这对于通用应用程序是否可行?

这是我的 App.xaml 现在的样子:

<Application.Resources>
    <AppBar x:Key="GlobalBar" ClosedDisplayMode="Minimal">
        <!--Controls....-->
    </AppBar>
</Application.Resources>

但是我如何在 MainPage.xaml 上实现它?

遗憾的是,您不能完全按照自己的意愿行事....但您可以使用不同的方法来实现它。使用单个母版页 - 添加框架和单个 AppBar。框架将负责页面导航。我还将建议您在 UWP 应用程序中使用 commandBar 而不是 AppBar。 您可以在 MainPage.xaml 中将其用作 -

<Page
x:Class="App2.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App2"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.BottomAppBar>
    <AppBar>

    </AppBar>
</Page.BottomAppBar>

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
   <!--Your Code-->       
</Grid>

最快最简单的方法是创建一个带有 AppBar 和 Main Frame 的页面。

  1. 创建根页面。
  2. 添加应用栏。
  3. 添加框架并命名 东西(前根框架)
  4. 在构造函数或OnNavigatedTo中 rootPage 将 rootFrame 导航到您的 MainPage。

现在所有页面都有一个AppBar。在页面中,您可以使用 this.Frame.Navigate(...) 进行导航。在你的 AppBar 所在的 rootPage 中你可以 use rootFrame.Navigate(...)