Set the app bar button image at runtime

I am using the following code to set an image for a normal button, but it doesn't work for a control panel button

ImageBrush brush = new ImageBrush();
brush.ImageSource = new BitmapImage(new Uri("ms-appx:///Assets/logo.png"));
button.Background = brush;

      

I am also trying to change property Background

to property Content

, but it still doesn't work. Any solution for this?

+3


source to share


2 answers


You cannot set a background property on a button whose style was set to AppBarButtonStyle. (resource defined in StandardStyles.xaml in all Metro Store apps). Since the background property was not bound by the template to the background of the root grid, as it was done in the default style of the button.



To achieve this, you can set an image as the content of the button.

0


source


Use the Image

class instead of the app bar button.



+2


source







All Articles