如何将不同的 CommandBars (AppBars) 添加到 Windows Phone 8.1 应用程序中的 Hub 元素。我想为每个 Hub 部分设置一个不同的 CommandBar,但我不能在 Hub 部分中声明 CommandBar。所以我只能在 Hub 中使用一个 CommandBar。
问问题
1456 次
1 回答
1
您可以创建超过 4 个 AppBarButton 并使其不可见,然后更改每个 Hub 部分的 Visibility 属性。菜单按钮的方式相同。
样本:
<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# 文件(您必须为每个部分设置名称):
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;
}
}
于 2014-05-21T13:55:37.957 回答