多AppBar /命令栏的 [英] Multiple AppBar/CommandBar's

查看:136
本文介绍了多AppBar /命令栏的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早在Windows Phone的8,我能够使用多个AppBar,交换他们在某些支点的网页,但在Windows Phone的8.1,我不知道如何做到这一点还是这甚至可能。

Back in Windows Phone 8, I was able to to use multiple AppBar, swapping them on certain pivot pages but In Windows Phone 8.1, I'm not sure how to do this or is this even possible.

基本上我的情况,我有3枢轴页面。每个页面都需要有不同的命令栏,因为它需要有不同的控制。

Basically for my scenario, I've got 3 Pivot Pages. Each page needs to have a different CommandBar because it needs to have different controls.

时有人能告诉我我该怎么办呢?

Is someone able to show me how I can do this?

编辑:
code哪一个我用的Windows Phone 8执行此:

Code Which I used for Windows Phone 8 to execute this:

XAML:

<phone:PhoneApplicationPage.Resources>
<shell:ApplicationBar x:Key="AppBar1" IsVisible="True" IsMenuEnabled="True">
    <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1"/>
    <shell:ApplicationBar.MenuItems>
        <shell:ApplicationBarMenuItem Text="MenuItem 1"/>
    </shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>

<shell:ApplicationBar x:Key="AppBar2" IsVisible="True" IsMenuEnabled="True">
    <shell:ApplicationBarIconButton IconUri="/Images/appbar_button1.png" Text="Button 1" />
    <shell:ApplicationBarIconButton IconUri="/Images/appbar_button2.png" Text="Button 2" />
    <shell:ApplicationBar.MenuItems>
        <shell:ApplicationBarMenuItem Text="MenuItem 1" />
        <shell:ApplicationBarMenuItem Text="MenuItem 2" />
    </shell:ApplicationBar.MenuItems>
</shell:ApplicationBar>

C#:

private void MainPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        switch (MainPivot.SelectedIndex)
        {
            case 0:
                ApplicationBar = this.Resources["AppBar1"] as ApplicationBar;
                break;
            case 1:
                ApplicationBar = this.Resources["AppBar2"] as ApplicationBar;
                break;
        }
    }

基本上切换的AppBar当PivotPage被改变。

Basically switches the the AppBar when the PivotPage is changed.

推荐答案

在WP8.1 RT,你有一个属性<一个href=\"http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.page.bottomappbar\">BottomAppBar你的网页。它的工作原理pretty大致相同(除了它的扩展)作为旧应用程序任务栏 - 你可以用它设置<一个href=\"http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.commandbar.ASPx\">CommandBar.我创建了我的命令栏在code和它的作品,你可以尝试这样的:

In WP8.1 RT, you have a property BottomAppBar of your Page. It works pretty much the same (apart it's extended) as old ApplicationBar - you can set it with CommandBar. I've created my command bars in code and it works, you can try like this:

// prepare your CommandBars - run method somewhere in the constructor of the page:
CommandBar firstBar;
CommandBar secondBar;

private void PrepareAppBars()
{
    firstBar = new CommandBar();
    firstBar.IsOpen = true;
    AppBarButton FirstBtn = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/first.png") } };
    FirstBtn.Label = "First";
    FirstBtn.Click += FirstBtn_Click;
    FirstBtn.IsEnabled = true;
    // Similar for second button
    AppBarButton SecondBtn = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/second.png") } };

    firstBar.PrimaryCommands.Add(FirstBtn);
    firstBar.PrimaryCommands.Add(SecondBtn);

    // define also SecondaryCommands

    // simlar secondBar
    secondBar = new CommandBar();
    secondBar.IsOpen = true;
    // ...
}

// then you can surely switch them like this:

private void MainPivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    switch (MainPivot.SelectedIndex)
    {
        case 0:
            BottomAppBar = firstBar ;
            break;
        case 1:
            BottomAppBar = secondBar ;
            break;
    }
}

这篇关于多AppBar /命令栏的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆