2011-04-27 209 views
7

我知道很多人问WPF按钮的背景图像,这是可能的,但我想问如何将外部图像(从Internet)添加到按钮的背景。有没有办法?WPF按钮与外部背景图像

回答

9

设定明确使用图像刷按钮的背景:

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

点击按钮后,按钮的界面从背景图像变为无,并在一个循环中恢复一个,我们如何解决它? – icaptan 2011-08-17 03:38:40

5

选择的答案是正确的,并改变在C#代码背景:

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

都正确。

+0

我怎样才能从按钮背景从ImageBrush中读取BitmapImage?它会返回SolidBrush。 – RollRoll 2014-07-21 14:53:57