【发布时间】:2014-05-18 17:52:30
【问题描述】:
当我的 Windows Phone 8.1 应用页面中的数据透视项发生更改时,我需要更改页面底部的 AppBar。我发现的所有示例都与 Silverlight Windows Phone 7/8 应用程序相关,不适用于通用应用程序 Windows Phone 8.1。
<AppBar x:Name="AppBar1" Visibility="Visible">
<CommandBar>
<AppBarButton x:Name="Save" Icon="save" Label="Save" Click="AppBarButton_Click" />
<AppBarButton x:Name="Cancel" Icon="cancel" Label="Cancel" Click="AppBarButton_Click" />
</CommandBar>
</AppBar>
<AppBar x:Name="AppBar2" Visibility="Collapsed">
<CommandBar x:Name="AppBar2">
<AppBarButton x:Name="Add" Icon="save" Label="Add" Click="AppBarButton_Click" />
</CommandBar>
</AppBar>
【问题讨论】:
-
你可以看看this question。
-
谢谢@Romasz - 我希望我能在设计师中做到这一点,然后只显示/隐藏合适的。您是说这是不可能的,您必须在运行时以编程方式创建 AppBars?
-
可以在运行时创建 AppBar (CommandBars) - 但 AFAIK 你必须在代码中以编程方式(而不是在 xaml 中)。正如我在 XAML 中使用资源尝试过的那样,它不起作用。你可以准备几个commandBars是代码,然后切换它们。
-
@Romasz 好的,我认为这给出了我需要知道的内容!谢谢!
-
您可以在 XAML 中将 CommandBars 创建为资源,并在代码隐藏中的数据透视项更改时将它们中的任何一个分配给 Page.BottomAppBar。
标签: c# windows-phone-8.1 win-universal-app