如何在Windows Phone 8.1中添加AppBar

时间:2014-05-07 22:22:36

标签: .net mobile windows-phone-8 windows-phone windows-phone-8.1

在Windows Phone 8中,它很容易添加App Bar并进行管理,但现在我测试新的Windows Phone 8.1 SDK以构建具有新Geofencing功能的项目,但我不知道如何添加App应用程序栏。

3 个答案:

答案 0 :(得分:43)

在Windows Phone 8.1中,我们可以使用BottomAppBar添加App Bar。通常我们使用CommandBar来创建基本的BottomAppBar。 CommandBar包含两个集合:PrimaryCommandsSecondaryCommands,与Windows Phone 8中的shell:ApplicationBar.Buttonsshell:ApplicationBar.MenuItems类似。

请阅读此演示,我们创建一个带有两个按钮的CommandBar:ZoomOut和ZoomIn,以及两个menuItem:Test01和Test02:

<Page.BottomAppBar>
    <CommandBar IsSticky="True" x:Name="appBar">
        <CommandBar.PrimaryCommands>
            <AppBarButton Icon="ZoomOut" IsCompact="False" Label="ZoomOut"/>
            <AppBarButton Icon="ZoomIn" IsCompact="False" Label="ZoomIn"/>
        </CommandBar.PrimaryCommands>
        <CommandBar.SecondaryCommands>
            <AppBarButton Label="Test01"/>
            <AppBarButton Label="Test02"/>
        </CommandBar.SecondaryCommands>
    </CommandBar>
</Page.BottomAppBar>

编辑:现在代码是正确的!

答案 1 :(得分:3)

这是另一种方式。之后一直滚动到XAML的顶部,单击第一个文本/字符串<phone:PhoneApplicationPage,您可以按F4以显示“公共”选项,或者您只需单击它然后转到属性并按“Common”,您将看到一个名为“ApplicationBar”的新选项。这种方式要好得多,你可以用这种方式创建一个新的。

答案 2 :(得分:2)

使用方法创建类

public static void AddNewAppBarinPage(Page myPage)
{
   CommandBar cbar = new CommandBar { ClosedDisplayMode = AppBarClosedDisplayMode.Minimal };
   AppBarButton appBarButton = new AppBarButton { Label = "Audio" };
   cbar.PrimaryCommands.Add(appBarButton);
   myPage.BottomAppBar = cbar;
}

在Page:

中使用
AppBarCustom.AddNewAppBarinPage(this);