.NET Maui How to inherit from a custom control

64 Views Asked by At

I have a custom control that includes base functionality, and I want to create other custom controls that inherit from it. And that's where I start running into compiler errors. Here is the relevant portion of the base class.

public partial class MyBaseControl : ContentView
{
    public MyBaseControl()
    {
        InitializeComponent();
        ...
    }
    ...
}

What I WANT to do is build another custom control that is all of that and a bit more.

public partial class MyCustomControl : MyBaseControl
{
    public MyCustomControl()
    {
        InitializeComponent();
        ...
    }
    ...
}

It give me compiler errors, saying that the partial class definition has a different base type... and it does, because a section of generated code still has it as ContentView.

Is there any way to do this? I want to build off both the xaml and cs of MyBaseControl and add to them for MyCustomControl. I really don't want to create multiple copies of MyBaseControl and then rename them to the new control type... a bug found in one would have to be corrected in all. And I really don't want the cluttered code of simply loading down MyBaseControl with all the different options for the several other controls I want to derive from it.

Is there a way to do what I want?

0

There are 0 best solutions below