代码之家  ›  专栏  ›  技术社区  ›  TK.

Winform控件上的c#WPF透明度

  •  7
  • TK.  · 技术社区  · 17 年前

    我有一个WPF控件,我想覆盖到WinForms应用程序上。因此,我尽职尽责地创建了一个元素主机,它可以显示以下WPF对象:

    <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只是在屏幕上删除它们。

    dialogHost = new ElementHost(); 
    dialogHost.Child = dialog;
    dialogHost.BackColorTransparent = true;
    dialogHost.BringToFront();  
    dialogHost.Show();
    

    有什么我应该做而我没有做的吗?

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

    有什么有用的文章吗?

    注:此问题与 this question

    4 回复  |  直到 9 年前
        1
  •  7
  •   micahtan    17 年前

    我想你遇到了麻烦 airspace issue . 好了,你不能混合使用WPF透明和ElementHost透明,因为ElementHost拥有空域。

    也许你可以考虑将更多的WiFrm应用移植到WPF?

        2
  •  2
  •   Community Mohan Dere    9 年前

    您应该阅读以下内容: Black background before loading a wpf controll when using ElementHost 躲起来,;展示它(不酷但有效)

        3
  •  0
  •   Artur Carvalho    17 年前

    这似乎是互操作 airspace

        4
  •  -1
  •   user112889    17 年前

    您可能已经尝试过了,但是在用户控件上设置不透明度如何?