2011-04-27 163 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