c#WPF对Winform控件的透明度

TK.*_*TK. 8 c# wpf controls transparency winforms

我有一个WPF控件,我想覆盖到WinForms应用程序.所以我尽职尽责地创建了一个可以显示以下WPF对象的Element Host:

<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>
Run Code Online (Sandbox Code Playgroud)

问题是WinForm表单上的控件不呈现,WPF只是在屏幕上删除它们.

元素主机创建如下:

dialogHost = new ElementHost(); 
dialogHost.Child = dialog;
dialogHost.BackColorTransparent = true;
dialogHost.BringToFront();  
dialogHost.Show();
Run Code Online (Sandbox Code Playgroud)

有什么我应该做的,我不是吗?

是否存在关于在Winforms上显示透明WPF控件的已知问题?

任何可能有帮助的艺术品?

注意:这个问题与这个问题有关

mic*_*tan 7

我想你正遇到一个空域问题.AFAIK,您不能混合WPF透明度和ElementHost透明度,因为ElementHost拥有空域.

关于创建非矩形hwnds以托管WPF内容的链接中有一个简短的模糊,这可能会让你更远.

也许你可以考虑将更多的WinForms应用程序迁移到WPF?