简体   繁体   English

将Windows.Controls.UserControl转换为Windows.Forms.Control

[英]Casting Windows.Controls.UserControl to Windows.Forms.Control

我们可以将WPF用户控件转换为表单控件吗?

I'm sorry you can't. 对不起,你不能。 WPF works very differently internally from Winforms: Winforms uses the controls provided by the Windows OS (where each control has a window handle), where WPF uses DirectX to do the painting. WPF内部的工作方式与Winforms完全不同:Winforms使用Windows操作系统提供的控件(每个控件都有一个窗口句柄),WPF使用DirectX进行绘制。

You can host WPF controls inside winforms applications (EDIT) and vice versa (with limitations) but that is perhaps not what you're after. 您可以在winforms应用程序(EDIT)中托管WPF控件,反之亦然 (有限制),但这可能不是您所追求的。

I tried this out: 我试过这个:

TouchScreenWPF touchUI = new TouchScreenWPF();
ElementHost elementHost = new ElementHost();
elementHost.Child = touchUI;
Control userControl = new Control();
userControl.Controls.Add(elementHost);

The form contains the usercontrol, but does not display anything when I include a WPF User control. 表单包含usercontrol,但在包含WPF用户控件时不显示任何内容。 It works with a single button though... Am I missing something there? 它只用一个按钮就可以......我错过了什么吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM