Windows 8应用程序上的全局应用程序栏

Xst*_*hef 8 c# xaml appbar microsoft-metro windows-8



我正在开发一个Windows 8应用程序项目.我正在使用Visual Studio 2012和它的预定义模板(GroupedPage,SplitPage,ItemsPage).
这时我需要添加一个App栏.我选择的方式是创建一个并在所有页面上显示它.我读这篇文章:http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj150604.aspx

要在我的项目中包含它,我将全局页面设置为App.xaml上的起始页面

protected async override void OnLaunched(LaunchActivatedEventArgs args)
...
  if (!rootFrame.Navigate(typeof(GlobalPage), args.Arguments))
                    throw new Exception("Failed to create initial page");
...
Run Code Online (Sandbox Code Playgroud)

在Global页面上,我正在更改OnLaunched方法,以便进入真正的主页面:

 rootPage = e.Parameter as Page;            
            frame1.Navigate(typeof(MainPage), this);
Run Code Online (Sandbox Code Playgroud)

我为按钮添加了事件订阅,例如

 private void ButtonBlogList_Click(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(BlogListManagement), this);
        }
Run Code Online (Sandbox Code Playgroud)

启动应用程序后,将显示应用程序栏,我可以使用内部的应用程序按钮进行导航,但在第一次导航后,AppBar不会显示在目标页面上.

知道我的错误吗?
谢谢你的帮助.

Dea*_*sen 10

你想要做的是在LayoutAwarePage上设置AppBar,因为所有页面都来自该页面.对于AppBar的内容,您可能希望使用UserControl,以便于编码和样式化.

首先创建UserControl:

<UserControl
x:Class="AppBarGlobal.AppbarContent"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppBarGlobal"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">

<StackPanel Orientation="Horizontal">
    <Button
        Content="1"
        Style="{StaticResource AppBarButtonStyle}" />
    <Button
        Content="2"
        Style="{StaticResource AppBarButtonStyle}" />
</StackPanel> </UserControl>
Run Code Online (Sandbox Code Playgroud)

然后在LayoutAwarePage的构造要创建AppBar,内容设置为用户控件,并将其添加到您的网页上BUTTOM或TopAppBar - 在此示例中我使用BottomAppBar并设置寄托都在consturctor,这样:

    public LayoutAwarePage()
    {
        bar = new AppBar();
        bar.Content = new AppbarContent();
        this.BottomAppBar = bar;
        //and the remaining code for the constructor hereafter.
Run Code Online (Sandbox Code Playgroud)

这应该允许您在从WindowsAwarePage派生的所有页面上的Windows应用商店应用程序中拥有全局应用栏.