【问题标题】:How can i add AppBar in Windows Phone 8.1如何在 Windows Phone 8.1 中添加 AppBar
【发布时间】:2014-06-25 02:56:36
【问题描述】:

在 windows phone 8 中,添加和管理应用栏非常容易,但现在我测试新的 windows phone 8.1 SDK 以构建具有新地理围栏功能的项目,但我不知道如何添加应用栏应用程序。

【问题讨论】:

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


    【解决方案1】:

    在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>
    

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

    【讨论】:

    • IsSticky 在 WP 8.1 上没有任何作用
    • 可以放在app上面吗? (TopAppBar 可以说)
    • 我们不能这样做。在 windows phone 中,只有 BottomAppBar。
    • 查看此链接以使用 XAML 添加应用栏 -> msdn.microsoft.com/en-us/library/windows/apps/…
    【解决方案2】:

    这是另一种方式。之后一直滚动到 XAML 的顶部,单击第一个文本/字符串 &lt;phone:PhoneApplicationPage 您可以按 F4 以调出“通用”选项,或者您可以单击它并转到属性和按“Common”,您将看到一个名为“ApplicationBar”的新选项。这种方式好多了,你可以这样创造一个新的。

    【讨论】:

    • 如果我可以选择两个正确答案,这也是一个好方法,我会做的,谢谢:)
    【解决方案3】:

    用方法创建类

    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;
    }
    

    在页面中使用:

    AppBarCustom.AddNewAppBarinPage(this);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多