我正在开发一个windows phone 8.1应用程序。我在页面中使用了共享应用程序栏。在某个时间点,我需要更改全局应用栏的标签或图标。这可能吗?如何更改windows phone 8.1中共享应用程序栏的标签
你的想法会有帮助。
我正在开发一个windows phone 8.1应用程序。我在页面中使用了共享应用程序栏。在某个时间点,我需要更改全局应用栏的标签或图标。这可能吗?如何更改windows phone 8.1中共享应用程序栏的标签
你的想法会有帮助。
public MainPage()
this.InitializeComponent();
Loaded += MainPage_Loaded;
}
void MainPage_Loaded(object sender, RoutedEventArgs e)
{
CommandBar bottomCommandBar = this.BottomAppBar as CommandBar;
AppBarButton appbarButton_0 = bottomCommandBar.PrimaryCommands[0] as AppBarButton;
appbarButton_0.Label = "settings";
appbarButton_0.Icon = new SymbolIcon(Symbol.Setting);
}
这工作得很好..感谢您的帮助..! – user3736911 2014-09-30 14:01:36
如果存储在资源您的应用程序栏比你可以通过下面的代码访问它:
var commandBar = Application.Current.Resources["YouResourceKeyForAppBar"] as AppBar;
现在你必须给它一个参考,你可以修改里面的物品。如果以其他方式实施SharedApp,请编辑您的问题并告知更多相关信息。
BottomAppBar在WP8.1是CommandBar,在那里你会发现PrimaryCommands property,在其中你可能有AppBarButtons。如果你想改变例如标签(图标或其他任何东西),你应该能够做到这一点是这样的:
// change the label of the first button
((BottomAppBar as CommandBar).PrimaryCommands[0] as AppBarButton).Label = "New Label";
如果要经常改变AppBarButton的参数,使其更容易,你可以写一个简单的扩展方法:
/// <summary>
/// Get AppBarButton of AppBar - extension method
/// </summary>
/// <param name="index">index of target AppBarButton</param>
/// <returns>AppBarButton of desired index</returns>
public static AppBarButton PButton(this AppBar appBar, int index) { return (appBar as CommandBar).PrimaryCommands[index] as AppBarButton; }
当然这是与上面相同,但几乎没有什么更易于使用:
BottomAppBar.PButton(0).Label = "New label";
也许我可以提出一个替代的解决方案由于采用了8.1库在Windows.UI.ViewManagement命名空间即StatusBar和ApplicationView的标题
这将不利于出这种情况,但可能使事情变得更简单了另一个谁找在这个职位。
var titleName = "TITLE";
var statusBar = Windows.UI.ViewManagement.StatusBar.GetForCurrentView();
statusBar.ProgressIndicator.Text = titleName;
var applicationView = Windows.UI.ViewManagement.ApplicationView.GetForCurrentView();
applicationView.Title = titleName;
然后显示和隐藏,与控制:
await statusBar.ProgressIndicator.ShowAsync();
await statusBar.ProgressIndicator.HideAsync();
不幸的是,你可以在这里设置的唯一的事情就是标题。我不认为你可以为StatusBar设置一个自定义的样式。
你是怎么实现共享的appbar的? – 2014-09-25 08:18:37
@IgorKulman我已经在这个[link](http://msdn.microsoft.com/en-us/library/windows/apps/xaml/jj150604.aspx)之后实现了shred app bar。 – user3736911 2014-09-25 11:56:49