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
2010-10-06 07:52:50
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
2010-10-06 08:16:43
@Gishu: yeah, it works in both directions. Was going to mention that but got distracted.
jdv
2010-10-06 08:22:07
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
2010-10-06 11:29:06
+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
2010-10-06 11:41:51
I got the answer. I had to put a height and a width with the element host and the usercontrol!! Thanks CHEERS!! WPF!!
Kervin
2010-10-06 11:54:12