Visual Studio: Design a UserControl class that derives from an abstract base class
Posted
by Marcel
on Stack Overflow
See other posts from Stack Overflow
or by Marcel
Published on 2010-05-04T11:19:51Z
Indexed on
2010/05/04
14:08 UTC
Read the original article
Hit count: 369
Hi All,
I want to have an abstract base class for some of my custom UserControl
's. The reason is obvious: they share some common properties and methods (a basic implementation of some elements of an interface actually), and I want to implement them only once.
I have done this by defining my abstract base class:
public abstract class ViewBase : UserControl, ISomeInterface
Then I went to implement one of my views, as usual, with the designer:
public partial class SpecialView : UserControl //all OK
Up to here all is fine. Now I replace the derivation of my SpecialView
class with the abstract base class:
public partial class SpecialView : ViewBase //disrupts the designer
Now, the designer in Visual Studio 2008 won't work anymore, stating: The designer must create an instance of type 'ViewBase' but it cannot because the type is declared as abstract.
How can I circumvent this? I just do not want to have the same code copied for all those views.
Info: there is a question question with virtual methods, instead of abstract classes, but there is no suitable solution for me.
© Stack Overflow or respective owner