问题1:
WPF中在使用WindowsFormsHost调用WinFrom控件时,若在WindowsFormsHost上层添加了WPF控件,该控件不会显示出来。
<Grid>
<WindowsFormsHost Background="White">
<Winfrm:WebBrowser x:Name="WinFrmWebBrowser"/>
</WindowsFormsHost>
<!--运行时 Ellipse 不会显示出来-->
<Ellipse Width="100" Height="100" Fill="Red"/>
</Grid>

解决方案: 使用Popup对上层的WPF控件内容进行包装。
<Style TargetType="{x:Type local:MyBrowser}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:MyBrowser}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"

本文探讨了在WPF应用中使用WindowsFormsHost遇到的问题及解决方案。问题包括:1) WPF控件无法显示在WindowsFormsHost上方;2) 如何裁剪WindowsFormsHost的内容;3) WindowsFormHost不支持png透明背景。通过使用Popup包装WPF控件、设置WinForm控件的Region属性限制显示区域以及将多个WinForm控件放在同一Panel下解决这些问题。提供了示例和源代码下载链接。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



