我正在开发一个 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");
...
在 Global 页面上,我正在更改 OnLaunched 方法,以便进入真正的主页:
rootPage = e.Parameter as Page;
frame1.Navigate(typeof(MainPage), this);
我为按钮添加事件订阅,例如
private void ButtonBlogList_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(BlogListManagement), this);
}
启动应用程序后,会显示应用程序栏,我可以使用内部的应用程序按钮进行导航,但第一次导航后,AppBar不会显示在目标页面上。
你知道我的错误吗?
感谢您的帮助。
您想要做的是在 LayoutAwarePage 上设置 AppBar,因为所有页面都源自该页面。
对于 AppBar 的内容,您可能需要使用 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>
然后在 LayoutAwarePage 的构造函数中,您要创建 AppBar,将内容设置为 UserControl,并将其添加到页面上的 Buttom 或 TopAppBar - 在此示例中,我使用 BottomAppBar 并在构造函数中设置所有内容,如下所示:
public LayoutAwarePage()
{
bar = new AppBar();
bar.Content = new AppbarContent();
this.BottomAppBar = bar;
//and the remaining code for the constructor hereafter.
这应该允许您在派生自 LayoutAwarePage 的所有页面上的 Windows 应用商店应用程序中拥有一个全局应用程序栏。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)