Windows 8 应用程序上的全局应用程序栏 [英] Global App bar on windows 8 application

查看:27
本文介绍了Windows 8 应用程序上的全局应用程序栏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



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

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

To include this on my project, I set the Global page as start page on the App.xaml

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

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

On the Global page, I'm changing the method OnLaunched, in order to get to the real main page:

 rootPage = e.Parameter as Page;            
            frame1.Navigate(typeof(MainPage), this);

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

I add event subscription for buttons, like

 private void ButtonBlogList_Click(object sender, RoutedEventArgs e)
        {
            this.Frame.Navigate(typeof(BlogListManagement), this);
        }

启动应用后,显示App栏,我可以用里面的应用按钮导航,但是第一次导航后,目标页面上没有显示AppBar.

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

After launching application, the App bar is displayed, and I can navigate with the app button inside, but after the first navigation, AppBar is not displayed on the target page.

Any idea of my mistake ?
Thanks for your help.

推荐答案

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

What you want to do is to set the AppBar on the LayoutAwarePage since all pages derives from that page. For the AppBar's content you might want to use a UserControl, for ease of coding and styling.

首先创建UserControl:

First create the 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>

然后在要创建 AppBar 的 LayoutAwarePage 的构造函数中,将内容设置为 UserControl,并将其添加到页面上的 Button 或 TopAppBar - 在此示例中,我使用 BottomAppBar 并在构造函数中设置所有内容,像这样:

And then in the constructor of the LayoutAwarePage you want to create the AppBar, set the content to the UserControl, and add it to your Buttom or TopAppBar on the page - in this sample I use the BottomAppBar and set everthing in the consturctor, like this:

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

这应该允许您在派生自 LayoutAwarePage 的所有页面上的 Windows 应用商店应用中拥有一个全局应用栏.

This should allow you to have a Global App bar inside your Windows Store app on all the pages that derive from LayoutAwarePage.

这篇关于Windows 8 应用程序上的全局应用程序栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆