部分类继承

编程入门 行业动态 更新时间:2024-10-25 16:22:58
本文介绍了部分类继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为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 { //... }

更多推荐

部分类继承

本文发布于:2023-11-05 19:08:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561610.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!