【发布时间】:2012-01-20 10:25:00
【问题描述】:
如何以编程方式将按钮的背景设置为图像? 我知道如何在 XAML 中做到这一点,但在代码中,我一直卡住,我试过了
Button.Background = new ImageBrush{ ImageSource = "source" };
然后我得到了字符串无法转换为 ImageSource 的错误。
【问题讨论】:
标签: windows-phone-7 button imagesource
如何以编程方式将按钮的背景设置为图像? 我知道如何在 XAML 中做到这一点,但在代码中,我一直卡住,我试过了
Button.Background = new ImageBrush{ ImageSource = "source" };
然后我得到了字符串无法转换为 ImageSource 的错误。
【问题讨论】:
标签: windows-phone-7 button imagesource
Try:
Button.Background = new ImageBrush{ ImageSource = new BitmapImage(new Uri(imgPath, UriKind.Relative)) };
【讨论】: