【问题标题】:Hosting WPF UserControl in a transparent Windows.Form在透明的 Windows.Form 中托管 WPF UserControl
【发布时间】:2013-11-29 12:52:17
【问题描述】:

我需要将我的 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时,为了使其不可见,我需要继续拥有我@的所有ChildrenStrokes的不透明度987654327@ 到 1(这样我可以看到它们)。

我尝试使用TransparencyKey 属性,但它似乎不适用于ElementHost。我该如何解决这个问题,如何在 Form 和 UserControl 之间设置不同的不透明度?

【问题讨论】:

    标签: c# wpf winforms transparency elementhost


    【解决方案1】:

    由于 WPF 使用亚像素 alpha 渲染,这是不可能的 AFAIK,例如 winform 不可用的

    希望对你有所帮助

    【讨论】:

    【解决方案2】:

    如果您想托管在 Win Forms 上透明运行的 WPF 控件,请按照以下步骤操作

    • 创建 WPF 用户控件控件并设置背景为“透明”。

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

      public WinControl()
      {
          InitializeComponent();
      }
      protected override CreateParams CreateParams
      {
          get
          {
              CreateParams cp = base.CreateParams;
      
              cp.ExStyle |= 0x00000020;
              return cp;
          }
      }
      
    • 现在将 WPF 用户控件放在 Win 用户控件上并停靠 wpfusercontrol 到它的父级(赢得用户控制)。

    • 现在将 win 用户控件拖到 |Win 窗体上并停靠 win 用户控件 到它的父级(Form)

    你就完成了。

    【讨论】:

      【解决方案3】:

      您可以使用 Microsoft.Ink.dll 创建您自己的基于 WinForms 的 UserControl,如果您正在尝试这样做,它支持手写识别。

      【讨论】:

      • 拜托,你能链接任何参考吗?
      • 当然。我使用 Microsoft.Ink DLL 托管了一个小示例,转到 nmctl.codeplex.com,转到源代码树并下载 InkSample 目录。 Ink dll 应该在 C:\Windows\assembly 中找到...仅供参考,Visual Studio 不会自动在该目录和 C:\Windows\Microsoft.NET) 中找到相当多的库。 ..
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-02
      • 2016-11-07
      相关资源
      最近更新 更多