C# 带有外部背景图像的WPF按钮

C# 带有外部背景图像的WPF按钮,c#,wpf,C#,Wpf,我知道很多人问过WPF按钮的背景图像,这是可能的,但我想问一下如何将外部图像(来自互联网)添加到按钮的背景中。有办法吗?使用ImageBrush显式设置按钮的背景: <Button Content="Hello"> <Button.Background> <ImageBrush ImageSource="http://example.com/foo.jpg" /> </Button.Background> </

我知道很多人问过WPF按钮的背景图像,这是可能的,但我想问一下如何将外部图像(来自互联网)添加到按钮的背景中。有办法吗?

使用ImageBrush显式设置按钮的背景:

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

选择的答案是正确的,要更改C代码中的背景,请执行以下操作:


两者都是正确的。

单击按钮后,按钮的界面从背景图像变为空白,并在循环中还原,我们如何解决它?如何从按钮背景从ImageBrush读取位图图像?它返回SolidBrush。
ImageBrush brush1 = new ImageBrush();
BitmapImage image = new BitmapImage(new Uri(IMAGE_URL_HERE));
brush1.ImageSource = image;
button1.Background = brush1;