开发者

WPF button with external background image

开发者 https://www.devze.com 2023-02-28 18:56 出处:网络
I know a lot of people asked about background image of a WPF button开发者_JS百科 and it is possible, but I would like to ask how to add external image ( from Internet ) to the button\'s background . I

I know a lot of people asked about background image of a WPF button开发者_JS百科 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 ?


Set the button's background explicitly using an ImageBrush:

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消