5

如何以编程方式将按钮的背景设置为图像?我知道如何在 XAML 中做到这一点,但在代码中,我一直卡住,我试过了

Button.Background = new ImageBrush{ ImageSource = "source" };

但后来我得到字符串无法转换为 ImageSource 的错误。

4

1 回答 1

13
Try:
Button.Background = new ImageBrush{ ImageSource = new BitmapImage(new Uri(imgPath, UriKind.Relative)) };
于 2012-01-20T10:31:25.160 回答