How can i add AppBar in Windows Phone 8.1

╄→гoц情女王★ 提交于 2020-01-12 13:41:54

问题


In windows phone 8, its very easy to add an App Bar and manage it, but now i test new windows phone 8.1 SDK to build a project with new Geofencing feature but i don't know how to add an App Bar in the App.


回答1:


In Windows Phone 8.1, We can use BottomAppBar to add App Bar. Usually we use CommandBar to create basic BottomAppBar. CommandBar contains two collection: PrimaryCommands and SecondaryCommands, It's similar with shell:ApplicationBar.Buttons and shell:ApplicationBar.MenuItems in Windows Phone 8.

Read this demo please, we create a CommandBar with two buttons: ZoomOut and ZoomIn, and two menuItem:Test01 and 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>

Edit: Now the code is correct!




回答2:


Here's another way. Scroll all the way to the top of the XAML afterwards, click on the first text/string <phone:PhoneApplicationPage you can either press F4 in order to bring up the "Common" selection or you can just click on it and just go to properties and press "Common" and there you will see a new option called "ApplicationBar". This way is much better, you can create a new fresh one this way.




回答3:


Create Class with Method

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

use in Page:

AppBarCustom.AddNewAppBarinPage(this);


来源:https://stackoverflow.com/questions/23529527/how-can-i-add-appbar-in-windows-phone-8-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!