Global App bar on windows 8 application

前端 未结 1 2016
独厮守ぢ
独厮守ぢ 2021-01-12 05:44



I\'m working on a Windows 8 application project. I\'m using Visual Studio 2012 and it\'s predefined Templates (GroupedPage, SplitPage, ItemsPage).
At this time

相关标签:
1条回答
  • 2021-01-12 06:28

    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.

    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>
    

    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.
    

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

    0 讨论(0)
提交回复
热议问题