在 WP7 Silverlight 应用程序中以编程方式隐藏应用程序栏图标? [英] Hide Application Bar Icon Programmatically in a WP7 Silverlight Application?

查看:25
本文介绍了在 WP7 Silverlight 应用程序中以编程方式隐藏应用程序栏图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内置于 Silverlight 的 Windows Phone 7 应用程序.此应用程序使用应用程序栏.如果已购买应用程序,我想隐藏应用程序栏中的按钮之一.但是,我注意到 ApplicationIconButton 类没有公开可见性"属性.同时,我没有看到在运行时动态填充应用程序栏的方法.

I have a Windows Phone 7 application built in Silverlight. This application makes use of the application bar. If the has purchased the application, I want to hide one of the buttons in the application bar. However, I've noticed that the ApplicationIconButton class does not expose a "Visibility" property. At the same time, I did not see a way to dynamically populate the application bar at runtime.

有人可以对此提供一些见解吗?这可能吗?如果是这样,如何?

Can anybody provide some insight into this? Is this possible? If so, how?

谢谢!

推荐答案

应用程序栏按钮以基于索引的方式工作,而不是像您期望的那样基于对象.因此,每当您想对其执行特定操作(例如禁用)时,您都需要指定一个按钮索引.

Application bar buttons work in an index-based way rather than object-based like you would expect. Therefore, you need to specify a button index whenever you want to perform a specific action on it (e.g. disable).

例如:

ApplicationBarIconButton b = (ApplicationBarIconButton)ApplicationBar.Buttons[0];
b.IsEnabled = false;

话虽如此,您可以创建新的 ApplicationBarIconButton 实例并将它们传递给 ApplicationBar:

This being said, you can create new ApplicationBarIconButton instances and pass them to ApplicationBar:

for (int i = 0; i < 2; i++)
{
    ApplicationBarIconButton b = new ApplicationBarIconButton();
    b.Text = i.ToString();
    b.IconUri = new Uri("/Images/icon1.png", UriKind.Relative);
    ApplicationBar.Buttons.Add(b);
}

删除按钮时,您可以简单地使用 RemoveAt,前提是您知道要删除的按钮的索引:

When removing buttons, you can simply use RemoveAt, given that you know the index of the button to remove:

ApplicationBar.Buttons.RemoveAt(0);

这篇关于在 WP7 Silverlight 应用程序中以编程方式隐藏应用程序栏图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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