Programmatically set the button background for the image

How can I programmatically set the button background for an image? I know how to do this in XAML, but I'm constantly stuck in the code, I tried

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

but then I get an error that the string could not be converted to ImageSource.

+5
source share
1 answer
Try:
Button.Background = new ImageBrush{ ImageSource = new BitmapImage(new Uri(imgPath, UriKind.Relative)) };
+13
source

All Articles