Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF button with external background image

Tags:

c#

wpf

I know a lot of people asked about background image of a WPF button and it is possible, but I would like to ask how to add external image ( from Internet ) to the button's background . Is there a way ?

like image 350
Raptor Avatar asked Apr 27 '11 04:04

Raptor


2 Answers

Set the button's background explicitly using an ImageBrush:

<Button Content="Hello">
    <Button.Background>
        <ImageBrush ImageSource="http://example.com/foo.jpg" />
    </Button.Background>
</Button>
like image 133
Matt Hamilton Avatar answered Oct 17 '22 09:10

Matt Hamilton


The selected answer is correct, and 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.

like image 5
Raptor Avatar answered Oct 17 '22 07:10

Raptor