我该如何通过编程将按钮的背景设置为图像?我知道如何在XAML中实现,但是在代码中,我一直遇到问题。我尝试过
Button.Background = new ImageBrush{ ImageSource = "source" };
但是我遇到了一个错误,提示字符串无法转换为ImageSource。
我该如何通过编程将按钮的背景设置为图像?我知道如何在XAML中实现,但是在代码中,我一直遇到问题。我尝试过
Button.Background = new ImageBrush{ ImageSource = "source" };
但是我遇到了一个错误,提示字符串无法转换为ImageSource。
Try:
Button.Background = new ImageBrush{ ImageSource = new BitmapImage(new Uri(imgPath, UriKind.Relative)) };