在运行时设置appbar按钮的图像

时间:2013-02-09 08:32:11

标签: c# windows-8 windows-runtime

我使用以下代码为普通按钮设置图像,但它不适用于appbar按钮。

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

我也尝试将Background属性更改为Content属性,但它仍然无效。对此有何解决方案?

2 个答案:

答案 0 :(得分:2)

使用Image类代替appbar按钮。

答案 1 :(得分:0)

您无法将背景属性设置为按钮,该样式设置为AppBarButtonStyle。 (所有Metro Store应用程序中StandardStyles.xaml中定义的资源)。由于background属性不是模板绑定到根网格的背景,因此在默认的按钮样式中也是如此。

为此,您可以将图像设置为按钮的内容。

相关问题