Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
473 views
in Technique[技术] by (71.8m points)

windows phone 7 - Hide Application Bar Icon Programmatically in a WP7 Silverlight Application?

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?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

For example:

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

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

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

ApplicationBar.Buttons.RemoveAt(0);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...