2014-01-22 125 views
-1

如何在WindowsFormsHost的按鈕上設置背景圖像?如何在WindowsFormsHost中設置Button的BackgroundImage?

<WindowsFormsHost Name="wfbutton1" Width="200" Height="100" Background="White" Visibility="Visible" > 
    <wf:Button Height="23" Left="145" Top="127" wf:Name="button1" Width="75" 
       Click="button1_Click" Visible="True" FlatStyle="Flat" 
       BackgroundImage="C:\\Users\\Kvint\\Desktop\\Background.bmp" /> 
</WindowsFormsHost > 
+0

我不能鏈接到圖像 不工作 的BackgroundImage =「/ WpfApplication4;組件/圖像/ Background.bmp 「 不工作太 –

+0

我使用WindowsFormsHost的WinForms按鈕,WinForms按鈕有屬性BackgroundImage。 –

回答

0

給你的按鈕,像任何其他WPF元素的名稱:

<WindowsFormsHost ... > 
    <wf:Button x:Name="button1" ... /> 
</WindowsFormsHost > 

然後引用的代碼隱藏:

button1.BackgroundImage 
    = System.Drawing.Image.FromFile(@"C:\Users\Kvint\Desktop\Background.bmp"); 

如果你正在尋找一個純粹的XAML方法,我會把它留給別人。我不確定在這種情況下甚至是可能的。

+0

不,我不是在尋找純粹的XAML方法 button1.BackgroundImage = System.Drawing.Image.FromFile(@「C:\ Users \ Kvi​​nt \ Desktop \ Background.bmp」);不工作。沒有錯誤,也沒有圖像 –

+0

當我設置一個示例項目來測試它時工作。仔細檢查文件的位置和名稱。 –

+0

謝謝!它工作 –

相關問題