tags:

views:

32

answers:

2

Can we cast a WPF User Control to a form control??

+2  A: 

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.

You can host WPF controls inside winforms applications (EDIT)and vice versa (with limitations) but that is perhaps not what you're after.

jdv
you can however host a WPF Control in a WinForm app using the ElementHost control ; if that is what you're trying to do http://msdn.microsoft.com/en-us/library/ms742215.aspx
Gishu
@Gishu: yeah, it works in both directions. Was going to mention that but got distracted.
jdv
Thanks for the ElementHost. That is exactly what I needed. I have another problem though. With a WPF Button it works fine, but when I want to display a WPF User Control, it appears blank on the form. Do you what can be the reason?
Kervin
+1  A: 

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. It works with a single button though... Am I missing something there?

Kervin
I got the answer. I had to put a height and a width with the element host and the usercontrol!! Thanks CHEERS!! WPF!!
Kervin