Changing the application bar button at runtime

I am developing a WP7 application and the application should change the button icon in the application bar, given the status of the request. I tried:

if (App.Servers[index].ServerState == "Enabled")
{
  DetailsAppBar.btnStart.IconUri = new Uri("/AppBar/appbar.stop.rest.png");
}

else
{
  DetailsAppBar.btnStart.IconUri = new Uri("/AppBar/appbar.transport.play.rest.png");
}

This does not give me an error in the code, but it cannot compile .... any hints of this are welcome :)

thank

+5
source share
2 answers

ApplicationBar is a special control that does not behave like other Silverlight controls (see Peter Torr's related post ). One of the consequences is that the names specified in the XAML for the application panel buttons generate encoding fields that are always zero.

, btnStart DetailsAppBar null , , IconUri NullReferenceException.

, . , :

button = (IApplicationBarIconButton)ApplicationBar.Buttons[2];
+11

...

((ApplicationBarIconButton)ApplicationBar.Buttons[2]).IconUri = new Uri("/AppBar/appbar.stop.rest.png",UriKind.Relative);

:)

+8

All Articles