更改Hub的不同HubSections的命令栏 [英] Change Command Bar for different HubSections of an Hub

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

问题描述

大家好,我正在开发一个带有XAML和C#的Windows Phone 8.1运行时应用程序。

Hi everybody, I'm developing a Windows Phone 8.1 Runtime app with XAML and C#.

我有一个包含4个部分的Hub控件,我想更改命令栏内部某些AppBarButton的可见性取决于当前处于View中的Hub部分。

I have an Hub control with 4 sections and I would like to change the visibility of some AppBarButton inside the Command Bar depending on the Hub Section that is currently in View.

所以我注册了SectionsInViewChanged事件并且我将逻辑修改为回调内的命令栏。

So I registered for the SectionsInViewChanged event and I put the logic to modify the Command Bar inside the callback.

然而问题是这个事件的触发速度非常慢,所以AppBarButton的变化也非常慢。

However the problem is that this event is fired incredibly slowly and so the change of the AppBarButton is also very very slow.

我注意到了Windows Phone 8.1中内置的新闻应用程序也会根据视图中的部分更改命令栏,它确实非常好用。

I noticed that the built in News app inside Windows Phone 8.1 also change the command bar depending on the section in view and it works really really good.

所以我问自己这个应用程序使用什么样的事件/逻辑来实现这样的结果?

So I ask myself what kind of event/logic do this app use to achieve such a result?

任何人都可以帮助我有了它,这似乎真的很奇怪......

Can anyone help me with this, it seems really a strange thing...

提前感谢您的帮助。

推荐答案

您可以创建4个以上的AppBarButton并使其不可见,然后为每个Hub Section更改Visibility属性。菜单按钮的方式相同。

You can create more than 4 AppBarButton and make it invisible then you change Visibility Property for each per Hub Section. Same way for menu button.

示例:

<Page.BottomAppBar>
    <CommandBar>
        <CommandBar.PrimaryCommands>
            <AppBarButton x:Uid="Quick" Name="QuickAppBarButton" Label="quick" Icon="Pin" Click="AppBarButton_Click"/>
            <AppBarButton x:Uid="Quick" Name="AddAppBarButton" Label="add" Icon="Add" Click="AppBarButton_Click"/>
            <AppBarButton x:Uid="Quick"
                          Name="CalcAppBarButton"
                          Label="calculator"
                          Icon="Calculator"
                          Click="AppBarButton_Click" />
        </CommandBar.PrimaryCommands>
        <CommandBar.SecondaryCommands>
            <AppBarButton x:Uid="Accounts" Name="AccountsSecondaryButton" Label="accounts" Click="AccountsSecondaryButton_Click"/>
            <AppBarButton x:Uid="CurrencyMenu" Name="CurrencySecondaryButton" Label="currency" Click="CurrencySecondaryButton_Click"/>
            <AppBarButton x:Uid="Categories" Label="categories"/>
            <AppBarButton x:Uid="Settings" Label="settings" Name="SettingsSecondaryButton" Click="SettingsSecondaryButton_Click"/>
            <AppBarButton x:Uid="Tutorials" Label="tutorials"/>
            <AppBarButton x:Uid="About" Label="about"/>
        </CommandBar.SecondaryCommands>
    </CommandBar>
</Page.BottomAppBar>

和C#文件(您必须设置名称为每个部分):

And C# file (You must set name for every Section):

private void CoinsHub_SectionsInViewChanged(object sender, SectionsInViewChangedEventArgs e)
{
    if(CoinsHub.SectionsInView[0] == TransactionsHubSection)
    {
        QuickAppBarButton.Visibility = Visibility.Collapsed;
        AddAppBarButton.Visibility = Visibility.Visible;
        CalcAppBarButton.Visibility = Visibility.Collapsed;
    }
    else if (CoinsHub.SectionsInView[0] == OverviewHubSection)
    {
        QuickAppBarButton.Visibility = Visibility.Visible;
        AddAppBarButton.Visibility = Visibility.Collapsed;
        CalcAppBarButton.Visibility = Visibility.Collapsed;
    }
    else
    {
        QuickAppBarButton.Visibility = Visibility.Collapsed;
        AddAppBarButton.Visibility = Visibility.Visible;
        CalcAppBarButton.Visibility = Visibility.Visible;
    }
}


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

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