我正在为Windows Phone的一个单位换算,但我有一些问题类继承。
我有类测量这应该是我在程序的图形内容的顶级
公共类测量:的PhoneApplicationPage {公共无效转换(对象送) { supervar.Comparer(本); } 公共WindowsPhoneControinput supervar {搞定;组; } }
测量做不包含任何图形内容,但它的子类;而这里是我遇到的困难。
子类: Lengthco , Weigthco 和 Volumeco 需要从测量继承但是编译器说:
'Phoneapp1.Lengthco的分部声明声明不能指定不同的基类。
为什么会出现这种情况?
解决方案这是因为在XAML代码从另一个类继承:
<用户控件X: CLASS =myNamespace.MyControl> .... < /用户控件>
结果
公共部分类MyControl:用户控件 { // ... }如果你想继承其他基类的控制,你必须使用XAML中,也:
<测定X:类=myNamespace.MyControl> .... < /测定>公共部分类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 { //... }
更多推荐
部分类继承
发布评论