Home > DeveloperSection > Forums > WPF cannot implicitly convert system.drawing.bitmap to media.brush
jayprakash sharma
jayprakash sharma

Total Post:117

Posted on    December-18-2013 12:44 AM


 1 Reply(s)
 3127  View(s)
Rate this:

I want to change the background of a button manually in my WPF app.

I have an image imported into my resources and I want to do:

MyButton.Background = MyProject.Properties.Resources.myImage;

But I get the error:

cannot implicitly convert system.drawing.bitmap to media.brush

How can I do this??

ezra heywood
ezra heywood

Total Post:145

Posted on    December-18-2013 1:22 AM

Hi Jay,

You can create a BitmapImage from a Pack URI to that file.

 you have to create an ImageBrush from the BitmapImage to set the Background property.

var uri = new Uri("pack://application:,,,/images/myImage.jpg");

var image = new BitmapImage(uri);

MyButton.Background = new ImageBrush(image);

Don't want to miss updates? Please click the below button!

Follow MindStick