4

I've got a Control (mySubControl) which inherits from a UserControl (myAbstractControl) which is abstract. Now inside the Designer of mySubControl, there's always an error saying: Can't create instance of myAbstractControl.

I think the VS2010 Designer is trying to use the constructor of the myAbstractControl.

How can I prevent him from resulting in an error ?

This whole thing seems a bit creepy.

Let's see. I have a abstract BaseClass.

[TypeDescriptionProvider(typeof(ConcreteControlProvider))]
public abstract class AbstractControl : UserControl

It has a constructor containing code, which should be used by any inheriting class.

public AbstractControl(SuperVar myImportantSuperVar)
{
    myPrivateSuperVar = myImportantSuperVar;
    this.Loaded += new System.Windows.RoutedEventHandler(TreatMySuperVar);
}

Besides that, it needs the empty constructor to match the UserControl inheritance

public AbstractControl() {/*You won't really use me*/}

Now when there's a inheriting class (written by evil colleagues).

public partial class ConcreteControl: AbstractControl

It needs its own constructor and doesn't use my very important SuperVar treating method.

public ConcreteControl(SomeOtherVar notMyVar)
{
    // Do some useless things here
}

So there are TWO Problems now. Still I don't know why my designer is messing up and additionally my abstract classes construtor, vars and methods are ignored.

I already tried to use TypeDescriptionProviders (overriding GetReflectionType and CreateInstance) as noted in the linked entry, which didn't make difference.

So how can I solve this issues ?

Brad Larson
  • 170,088
  • 45
  • 397
  • 571
JJB2
  • 53
  • 1
  • 5
  • 1
    See http://stackoverflow.com/questions/6817107/abstract-usercontrol-inheritance-in-visual-studio-designer – ken2k Jan 03 '12 at 14:27
  • 1
    Well nice, it links to another page http://wonkitect.wordpress.com/2008/06/20/using-visual-studio-whidbey-to-design-abstract-forms/ but this one seems to be incomplete. – JJB2 Jan 03 '12 at 15:39
  • Is a constructor with the same signature defined in your inheritor? – Erik Dietrich Jan 03 '12 at 17:48
  • I have a generic solution in [an answer](http://stackoverflow.com/a/12594795/39396) to the other question. – Carl G Sep 26 '12 at 04:59

0 Answers0