Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在透明的Windows.Form中托管WPF UserControl_C#_Wpf_Winforms_Transparency_Elementhost - Fatal编程技术网

C# 在透明的Windows.Form中托管WPF UserControl

C# 在透明的Windows.Form中托管WPF UserControl,c#,wpf,winforms,transparency,elementhost,C#,Wpf,Winforms,Transparency,Elementhost,我需要将WPFUSerControl插入Windows.Form中。这是我的控制: <UserControl x:Class="WpfControlLibrary1.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

我需要将WPF
USerControl
插入
Windows.Form
中。这是我的控制:

<UserControl x:Class="WpfControlLibrary1.UserControl1"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             Background="Transparent">

    <InkCanvas x:Name="Ink" Background="Transparent" />

</UserControl>

要承载此控件,我使用
ElementHost
对象作为窗体的唯一控件。我需要有可能执行以下操作:当我将表单的不透明度设置为0时,为了使其不可见,我需要继续将我的
InkCanvas
的所有
子项
笔划
的不透明度设置为1(以便我可以看到它们)


我尝试使用
TransparencyKey
属性,但它似乎无法与
ElementHost
一起使用。如何解决此问题,以及如何在窗体和用户控件之间设置不同的不透明度?

AFAIK这是不可能的,因为WPF使用winform中不可用的亚像素alpha渲染


希望获得此帮助

您可以使用Microsoft.Ink.dll创建自己的基于WinForms的用户控件,以支持手写识别(如果您正试图这样做)。

如果您希望托管在Win Forms上透明运行的WPF控件,请执行以下步骤

  • 创建WPF usercontrol控件并设置background=“transparent”

  • 创建没有控件的Win用户控件,并编写以下内容 其后端的代码:

    public WinControl()
    {
        InitializeComponent();
    }
    protected override CreateParams CreateParams
    {
        get
        {
            CreateParams cp = base.CreateParams;
    
            cp.ExStyle |= 0x00000020;
            return cp;
        }
    }
    
  • 现在将wpfusercontrol放在Win用户控件和dock wpfusercontrol上 到其父级(赢得用户控制)

  • 现在在| win窗体上拖动win用户控件并停靠win用户控件 致其母公司(表格)


你已经完成了。

看看这篇文章,这可能是一个起点,但你可以像那样设计一个解决方案?请,你能链接任何参考资料吗?当然。我主持了一个使用Microsoft.Ink DLL的小示例,转到,转到源代码树并下载InkSample目录。应在C:\Windows\assembly中找到Ink dll。。。仅供参考,Visual Studio无法自动找到许多库,这些库在该目录中以及在C:\Windows\Microsoft.NET中都可用)。。。