Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.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.Controls.UserControl强制转换为Windows.Forms.Control_C#_Wpf - Fatal编程技术网

C# 将Windows.Controls.UserControl强制转换为Windows.Forms.Control

C# 将Windows.Controls.UserControl强制转换为Windows.Forms.Control,c#,wpf,C#,Wpf,我们可以将WPF用户控件转换为表单控件吗???很抱歉,您不能。WPF在内部的工作方式与Winforms非常不同:Winforms使用Windows操作系统提供的控件,其中每个控件都有一个窗口句柄,WPF使用DirectX进行绘制 您可以在winforms应用程序中承载WPF控件,反之亦然,但这可能不是您想要的 很抱歉,你不能。WPF在内部的工作方式与Winforms非常不同:Winforms使用Windows操作系统提供的控件,其中每个控件都有一个窗口句柄,WPF使用DirectX进行绘制 您可

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

很抱歉,您不能。WPF在内部的工作方式与Winforms非常不同:Winforms使用Windows操作系统提供的控件,其中每个控件都有一个窗口句柄,WPF使用DirectX进行绘制


您可以在winforms应用程序中承载WPF控件,反之亦然,但这可能不是您想要的

很抱歉,你不能。WPF在内部的工作方式与Winforms非常不同:Winforms使用Windows操作系统提供的控件,其中每个控件都有一个窗口句柄,WPF使用DirectX进行绘制

您可以在winforms应用程序中承载WPF控件,反之亦然,但这可能不是您想要的

我试过这个:

TouchScreenWPF touchUI = new TouchScreenWPF();
ElementHost elementHost = new ElementHost();
elementHost.Child = touchUI;
Control userControl = new Control();
userControl.Controls.Add(elementHost);
该表单包含usercontrol,但在包含WPF用户控件时不显示任何内容。它只需一个按钮就可以工作。。。我是不是遗漏了什么?

我试过:

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

该表单包含usercontrol,但在包含WPF用户控件时不显示任何内容。它只需一个按钮就可以工作。。。我遗漏了什么吗?

但是,您可以使用ElementHost控件在WinForm应用程序中托管WPF控件;如果这就是你想要做的@Gishu:是的,它在两个方向都起作用。我本来想提的,但是我分心了。谢谢ElementHost。这正是我所需要的。不过我还有一个问题。使用WPF按钮,它可以正常工作,但是当我想显示WPF用户控件时,它在表单上显示为空。您知道原因是什么吗?但是,您可以使用ElementHost控件在WinForm应用程序中托管WPF控件;如果这就是你想要做的@Gishu:是的,它在两个方向都起作用。我本来想提的,但是我分心了。谢谢ElementHost。这正是我所需要的。不过我还有一个问题。使用WPF按钮,它可以正常工作,但是当我想显示WPF用户控件时,它在表单上显示为空。你知道原因是什么吗?我知道答案了。我必须为元素主机和用户控件设置一个高度和宽度!!谢谢,干杯!!WPF!!我得到了答案。我必须为元素主机和用户控件设置一个高度和宽度!!谢谢,干杯!!WPF!!