0

I've a problem with two user controls, first of all I've a user control named "Base" and I want to inherit it from another user control named "MyControl" but the "Base" control is a partial class and the user control "MyControl" just have a public class, so I use a partial class in "MyControl", and I use an ElementHost to show "MyControl" but I've the error "Cannot implicity convert type MyControl to System.Windows.UIElement".
I try to add "MyControl" as a Child but it shows that error.
Help!

Edit: The clases looks like:

public partial class Base : UserControl 
{
}  
public partial class MyControl : Base  
{  
}  

And I want to do something like this:

public addControl() 
{  
    ElementHost _host = new ElementHost();  
    _host.Dock = Dockstyle.Fill;  
    _host.Child = _myControl;  
    panel.Control.Add(_host);
} 

The error is at _host.Child = _myControl;. At this point the object _myControl is initialized.

  • Include code to illustrate this structure. You can strip out the insides, just show the class definitions and possibly constructors if you don't think anything else is related. – Gary Jan 27 '17 at 15:19
  • NOTE: Partial is used to define a single class across multiple files. This is nothing to do with inheritance. – Andez Jan 27 '17 at 15:39

1 Answers1

0

Does it look something like?

public partial class Base : UIElement
{
}

public class myControl : Base
{
}

I'm not sure what you mean by

and I use an ElementHost

however, my guess is that you are trying to cast myControl as a ElementHost, but it isn't one. Or myControl doesn't implement something that is required from UIElement.

Let me know if that helps.

Gary
  • 3,254
  • 2
  • 27
  • 30