部分类继承 [英] Partial class inheritance

查看:102
本文介绍了部分类继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Windows Phone的一个单位换算,但我有一些问题类继承。



我有类测量这应该是我在程序的图形内容的顶级

 公共类测量:的PhoneApplicationPage 
{
公共无效转换(对象送)
{
supervar.Comparer(本);
}
公共WindowsPhoneControinput supervar {搞定;组; }
}



测量做不包含任何图形内容,但它的子类;而这里是我遇到的困难。



子类: Lengthco Weigthco Volumeco 需要从测量继承但是编译器说:

 'Phoneapp1.Lengthco的分部声明声明不能指定不同的基类。 



为什么会出现这种情况?


解决方案

这是因为在XAML代码从另一个类继承:

 <用户控件X: CLASS =myNamespace.MyControl> 
....
< /用户控件>



结果

 公共部分类MyControl:用户控件
{
// ...
}

如果你想继承其他基类的控制,你必须使用XAML中,也:



<预类=郎咸平的XML prettyprint-覆盖> <测定X:类=myNamespace.MyControl>
....
< /测定>



<预类=郎-CS prettyprint-覆盖> 公共部分类MyControl:测量
{
// ...
}


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?

解决方案

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 
{
    //...
}

这篇关于部分类继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆