WPF button with external background image

I know that many people ask about the background image of a WPF button, and this is possible, but I would like to ask how to add an external image (from the Internet) to the button background. Is there any way?

+7
source share
2 answers

Set the button background explicitly using ImageBrush:

<Button Content="Hello"> <Button.Background> <ImageBrush ImageSource="http://example.com/foo.jpg" /> </Button.Background> </Button> 
+9
source

The selected answer is also correct for changing the background in C # codes:

 ImageBrush brush1 = new ImageBrush(); BitmapImage image = new BitmapImage(new Uri(IMAGE_URL_HERE)); brush1.ImageSource = image; button1.Background = brush1; 

Both are correct.

+5
source

All Articles