Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Partial class inheritance

I am making a unit converter for windows phone but I'm having some problems with class inheritance.

I have the class Measurement which is supposed to be the top class for the graphical content in my program.

public class Measurement : PhoneApplicationPage
{
    public void Convert(object give)
    {
        supervar.Comparer(this);
    }
    public WindowsPhoneControinput supervar { get; set; }
}

Measurement does not contain any graphical content, but it's subclasses do; And here is where I am having difficulties.

The subclasses: Lengthco, Weigthco and Volumeco needs to inherit from Measurement but the compiler says:

"Partial declarations declarations of 'Phoneapp1.Lengthco' Must not specify different base classes".

Why is this happening?

like image 980
Jakob Danielsson Avatar asked Sep 07 '25 19:09

Jakob Danielsson


1 Answers

That happens because the XAML-code inherits from another class:

<UserControl x:Class="myNamespace.MyControl">
    ....
</UserControl>

results in

public partial class MyControl : UserControl
{
    //...
}

If you want to inherit the control from another base class, you must use that in XAML, too:

<Measurement x:Class="myNamespace.MyControl">
    ....
</Measurement>
public partial class MyControl : Measurement 
{
    //...
}
like image 161
Spontifixus Avatar answered Sep 09 '25 09:09

Spontifixus