Visual Studio Development Bookmark and Share   
 index > Visual Studio WPF Designer > Problem with ElementHost
 

Problem with ElementHost

I am trying to host a custom WPF controlin a C# WinForms project.

I have found several walkthroughs for this online:

1) http://msdn.microsoft.com/en-us/library/ms745781.aspx
2) http://www.codegod.de/webappcodegod/embedding-wpf-usercontrol-in-winforms-AID422.aspx
3) http://blog.paranoidferret.com/index.php/2008/06/24/wpf-tutorial-using-wpf-in-winforms/

The MSDN tutorial is slightly different in that it suggests creating a separate project to contain the custom control, whereas the other walkthroughs just add the WPF control to the current project.

I have tried both methods, and I get the same result. That is, when I add the ElementHost object to my WinForm, it does not detect any valid hostable content.

I have tried manually forcing it to host the content using the sample code provided in (1).

However, this results in a compile error at:

// Assign the WPF UserControl to the ElementHost control's
// Child property.
host.Child = uc;
//error CS0029: Cannot implicitly convert type 'WindowsFormsControlLibrary1.UserControl1' to 'System.Windows.UIElement'

Please let me know what could be the problem and why these walkthroughs are not working for me
Stuart13  Saturday, December 20, 2008 10:06 PM
I am trying to host a custom WPF controlin a C# WinForms project.

I have found several walkthroughs for this online:

1) http://msdn.microsoft.com/en-us/library/ms745781.aspx
2) http://www.codegod.de/webappcodegod/embedding-wpf-usercontrol-in-winforms-AID422.aspx
3) http://blog.paranoidferret.com/index.php/2008/06/24/wpf-tutorial-using-wpf-in-winforms/

The MSDN tutorial is slightly different in that it suggests creating a separate project to contain the custom control, whereas the other walkthroughs just add the WPF control to the current project.

I have tried both methods, and I get the same result. That is, when I add the ElementHost object to my WinForm, it does not detect any valid hostable content.

I have tried manually forcing it to host the content using the sample code provided in (1).

However, this results in a compile error at:

// Assign the WPF UserControl to the ElementHost control's
// Child property.
host.Child = uc;
//error CS0029: Cannot implicitly convert type 'WindowsFormsControlLibrary1.UserControl1' to 'System.Windows.UIElement'

Please let me know what could be the problem and why these walkthroughs are not working for me

Hi,

I am having exactly the same problem using VS2008. I haven't yet tried setting the Child explicitly by setting it to an instance of my wpf control. Did you ever manage to solve the problem using the VS UI?

Thanks
Blair
  • Edited byBlair Sutton Monday, September 07, 2009 7:32 PMmore specific.
  •  
Blair Sutton  Monday, September 07, 2009 7:28 PM

You can use google to search for other answers

Custom Search

More Threads

• Can't load XAML program at Visual Studio 2008
• Getting the designer to see my styles
• Error in VS 08
• Copy a DataGrid to the Clipboard C#
• December CTP Installation trouble
• Application for Blackberry
• More training videos/ tutorials for the Expression Interactive Designer?
• blue screen when starting a WPF app
• Cannot add content to object of type 'TestApp.Core.PageControl
• WPF designer _slooooow_