views:

28

answers:

2

I have two UserControl classes, RequiredFields and OptionalFields. I wanted to have a base class, Fields, that would inherit from UserControl and contain methods that both RequiredFields and OptionalFields would use. However, when I try to do that, I get the following error:

Partial declarations of 'MyNamespace.OptionalFields' must not specify different base classes

Here are my class definitions:

public partial class OptionalFields : Fields

public partial class RequiredFields : Fields

public abstract class Fields : UserControl

Even if I make Fields a partial class instead of abstract, or if I make it a regular non-abstract non-partial class, I get the same error.

Is what I'm wanting to do possible/reasonable? If not, what is the best way of sharing methods between UserControl instances?

+2  A: 

Do you have an OptionalFields.xaml? If so, it is automatically generating OptionalFields.g.cs which contains the C# code that the XAML represents. It contains a class that inherits from UserControl (or whatever the XAML's root element is).

Try changing the root element in the XAML file to Fields.

chilltemp
yup, you probably have still <UserControl> in your xaml instead of <local:Fields> or whatever.
John Gardner
That was the problem!
Sarah Vessels
Also, definitely shouldn't have my base class be `abstract` since then any user control that inherits from it will throw errors in the design view, saying it can't create an instance of the base class.
Sarah Vessels
A: 

Do you need to updated the other side of the partial? I.e. is OptionalFields.Designer.cs inheriting from UserControl still?

Edit: sorry being too winforms, I of course mean OptionalFields.xaml

chillitom