C#WPF在Winform控件上的透明度 [英] c# WPF transparency over Winform controls
问题描述
我有一个WPF控件,我想将其覆盖到WinForms应用程序上。因此,我忠实地创建了一个可以显示以下WPF对象的元素主机:
I have a WPF control that I would like to overlay onto a WinForms application. So I have dutifully created a Element Host that can show the following WPF object:
<UserControl x:Class="LightBoxTest.LightBox"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300" Background="Transparent">
<Grid Name="dialogHolder" Background="Transparent" Opacity="1">
<Rectangle Name="rectangle1" Stroke="White" Fill="Black" RadiusX="10" RadiusY="10" Opacity="0.5" />
<StackPanel Name="stackPanel1" Background="Transparent" Height="300" VerticalAlignment="Top">
<Rectangle Name="spacer" Opacity="0" Stroke="Gray" Fill="White" RadiusX="10" RadiusY="10" Height="100" Width="300" />
<Grid Height="100" Name="contentHolder" Width="250">
<Rectangle Name="dialog" Stroke="Gray" Fill="White" RadiusX="10" RadiusY="10" Height="100" Width="250" />
</Grid>
</StackPanel>
</Grid>
</UserControl>
问题在于WinForm窗体上的控件无法呈现,而WPF只是在控件上消除了它们。屏幕。
The trouble is that the Controls on the WinForm Form do not render and the WPF just obliterates them on the screen.
元素主机的创建方式如下:
The element host is created like:
dialogHost = new ElementHost();
dialogHost.Child = dialog;
dialogHost.BackColorTransparent = true;
dialogHost.BringToFront();
dialogHost.Show();
我应该做些什么吗?我不是吗?
Is there something I should be doing and Im not?
是否存在有关对Winforms显示透明的WPF控制的已知问题?
Are there known issues about showing transparent WPF controls over Winforms?
是否有任何有用的文章?
Any articals that may help?
注意:此问题与此问题
推荐答案
我认为您遇到了空域问题。 AFAIK,因为ElementHost拥有领空,所以您不能混合使用WPF透明度和ElementHost透明度。
I think you're running into an airspace issue. AFAIK, you can't mix WPF transparency and ElementHost transparency since the ElementHost owns the airspace.
链接中有一小段关于创建非矩形Hwnd来承载WPF的信息。
There's a short blurb in the link about creating non-rectangular hwnds to host WPF content, and that may get you farther.
也许您可以考虑将更多WinForms应用程序迁移到WPF?
Perhaps you can consider migrating more of the WinForms app to WPF?
这篇关于C#WPF在Winform控件上的透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!