0

Well the title should actually explain the problem quite well. Consider I create a new UserControl, however in my application many of those elements share a common code, and they are part of a "subgroup" of user controls.

The logical thing is to "inject" a class between the generated CustomUserControl and UserControl;

Something akin to:

public abstract class CommonCustomControl : UserControl 
{ 
    public CommonCustomControl(int v, string other) {
    }
}
public partial class CustomUserControl : CommonCustomControl
{ 
    CustomUserControl(int v, string other) : base(v, other) {
    }
}

Now the problem with this is, is that the class is only "partially" generated by visual studio. So changing the generated CustomUserControl class gives an error:
"Base class differs from declared in other parts"

How can I prevent this error? While still being able to actually design my user control element in visual studio's gui designer?

I have tried already the answer provided by this question. But it seems to not work at all. (Maybe since that talks about winforms instead of the WPF version)

[TypeDescriptionProvider(typeof(AbstractControlDescriptionProvider<InterfaceHandler, UserControl>))]
public abstract class CommonCustomControl : UserControl
{
    private readonly int _v;
    private readonly string _other;

    public CommonCustomControl(int v, string other) {
        _v = v;
        _other = other;
    }
}

public partial class CustomUserControl : CommonCustomControl
{
    public CustomUserControl(int v, string other) : base(v, other) {
    }
}

What goes wrong?

Community
  • 1
  • 1
paul23
  • 8,799
  • 12
  • 66
  • 149

1 Answers1

0

You only have your C# code on view here but I'll take a punt at what this might be.

The UserControl you are declaring inherits from a base class. The UserControl is also a partial class.

Partial classes normally mean that there is other code for this class elsewhere.

The error is stating that the base class is different between the two partial classes.

If you do not have your own second partial class for this UserControl (i.e. it is not just a class, but an actual User Control), then I assume the rest of the definition will be in the XAML.

Depending on how you are implementing your controls:

You may have this:

<UserControl x:Class="NamespaceHere.CustomUserControl"> ... </UserControl>

It should look like this:

<CommonCustomControl x:Class="NamespaceHere.CustomUserControl"> ... </CommonCustomControl>

If not, could you show your XAML too?

Steve Padmore
  • 1,710
  • 1
  • 12
  • 18