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);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…