A concrete implementation of a generic form not working in the designer

I have a base class defined below (I also use DevExpress components):

public abstract partial class BaseFormClass<R> : XtraForm where R : DataRow
{
  ...
}

      

Unlike what I've read from other sources, I can still create this class. I didn't need to create a specific class for it to do this. But, when I create a specific class coming from it (as shown below), that class won't work in the designer.

public partial class ConcreteFormClass : BaseFormClass<StronglyTypedRow>
{
  ...
}

      

I am getting this message:

The designer cannot be shown for this file because none of the classes inside it can be designed. the designer inspected the following classes in the file: ConcreteFormClass --- Base class 'BaseFormClass' could not be loaded. Ensure the link is collected and that all projects have been built.

Has anyone seen this before? Any known workaround?

+1


a source to share


2 answers


Sorry, but it just won't work (which is a shame - I've wanted you to do that too). The problem lies in the basic methodology of the designer.

To present you with a model of your form, it is not really trying to create the form itself; if that happened, you would run into other problems - what if your form doesn't have a parameterless constructor? Instead, it actually instantiates your form's base class. It then sneaks through your method InitializeComponents()

and "layers" of all the controls you defined there into the base shape.



So, it's obvious why this won't work. You can create an instance BaseFormClass

because in order to create it, it creates an instance XtraForm

that is concrete. But you cannot create an instance ConcreteFormClass

, because for that it will need to create an instance BaseFormClass

which is abstract.

The easiest workaround for this is to just make it BaseFormClass

non-abstract. (If you want to make absolutely sure that no one else can create it, perhaps you can make the default constructor private? I'm not sure if a designer can handle this, but I don't understand why it couldn't.) Sucks, but this is it. a life. Complain to Microsoft and it might be better in Visual Studio 2012.

+4


a source


It looks like a really similar problem to get the designer to render forms with an abstract base class. I haven't done any general inheritance, but you could at least try my approach and see if it works.

Edit: Yes ok, just tried it, my solution works for sure. You just need to change the definition of middle classes and definition of shapes (wrapped in #if DEBUG

)



Let me know if you can try!

0


a source







All Articles