John
John

Reputation: 35

WPF - The following type was expected: UIElement

       <ElementHost>
        <dc:MyControl Name="MyControl3"  ShowScrollBars="True" Enabled="true" AutoScroll="True" />
        </ElementHost>

My project builds ok, but dc:MyControl is underlined saying: The specified value cannot be assigned. The following type was expected: UIElement

Is there a way around this? Thanks

Upvotes: 0

Views: 5835

Answers (1)

Sheridan
Sheridan

Reputation: 69979

I see a few possible reasons for your error from your code exerpt.

The first is that the ElementHost control is actually a Windows Forms control and so shouldn't be used in XAML at all. If you want to host a Windows Forms control in a WPF Application, then you should be using a WindowsFormsHost control instead. In this case, the Child element should be or extend the type System.Windows.Forms.Control.

If however, you are trying to host a WPF element in a Windows Forms Application, then you should be using the ElementHost control, but you should ensure that the Child element extends the UIElement class as it requires... from the linked page:

[The Child property] Gets or sets the UIElement hosted by the ElementHost control.

You can find out further information from the Walkthrough: Hosting a WPF Composite Control in Windows Forms and Walkthrough: Hosting a Windows Forms Control in WPF by Using XAML pages on MSDN.

Upvotes: 1

Related Questions