Add different CommandBars to Hub Element

半腔热情 提交于 2019-12-08 12:15:24

问题


How can I add different CommandBars (AppBars) to an Hub element in Windows Phone 8.1 app. I want to have a different CommandBar for each Hub Section, but I can't declare the CommandBar in the Hub Section. So I can only use one CommandBar in the Hub.


回答1:


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.

Sample:

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

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


来源:https://stackoverflow.com/questions/23661979/add-different-commandbars-to-hub-element

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