2014-01-22 70 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

谢谢!它工作 –

相关问题