如何在WindowsFormsHost中设置按钮的背景图像?

时间:2014-01-22 14:49:21

标签: c# wpf xaml background windowsformshost

如何在WindowsFormsHost

按钮上设置背景图片
<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 >

1 个答案:

答案 0 :(得分:0)

为您的按钮命名,就像任何其他WPF元素一样:

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

然后在代码隐藏中引用它:

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

如果您正在寻找纯粹的XAML方法,我会将其留给其他人。在这种情况下,我不确定它是否可能。