部分声明不得指定不同的基类 [英] Partial Declarations must not specify a different base class

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

问题描述

我一直面临一个错误,告诉我部分声明不能指定不同的基类。

I've been facing an error that tells me that the partial declarations must not specify a different base class.

public partial class MainWindow : Shape
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Stretch = System.Windows.Media.Stretch.Fill;
            this.StrokeLineJoin = PenLineJoin.Round;
        }



我收到错误:


I get error from :

public partial class MainWindow : Shape



'MainWindow'给出了关于指定不同基数的错误。我如何纠正这个错误?



我的XAML目前是默认的:


The 'MainWindow' gives me error about the specifying of a different base. How do i go about rectifying this error?

My XAML currently, is the default one:

   <Window x:Class="Triangle.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525">
    <Grid>

    </Grid>
</Window>



我还没有编辑XAML中的任何内容,因为这些代码是我在网上找到的代码,并用它来试验是否或不工作。


I have yet to edit anything from the XAML as this codes are codes i found somewhere from online and is using it to try out whether or not it work.

推荐答案

http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx [ ^ ]



上面概述了如何使用派生类而不是标准窗口或XAML中的Page类。本质上,XAML元素必须指定本地基类,包括其名称空间限定符。例如:



http://geekswithblogs.net/lbugnion/archive/2007/03/02/107747.aspx[^]

Above outlines how to use a derived class instead of the standard Window or Page classes in the XAML. Essentially the XAML element must specify the local base class including its namespace qualifier. e.g.:

<local:Shape x:Class="Triangle.MainWindow"

  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

  xmlns:local="clr-namespace:<your namespace here>"

  Title="MainWindow" Height="350" Width="525">
  <Grid>
 
  </Grid>
</Shape>


怎么样,怎么可能有另一个基类,形状?!通过XAML创建的窗口具有基类 Window ;并且您正在尝试添加一个基类。您是否知道在.NET中没有多重继承。从类的其他部分(部分声明)的继承列表中删除所有内容。



只允许弱继承多重继承,用于接口。因此,在每个部分中,您可以在继承列表中添加任意数量的接口(当然,您必须实现所有这些接口)。



顺便说一下,部分声明规则的实际结果是:在所有部分中,继承列表应该是不同的(除了空的列表)。如果其中一个部分中提到了基类或接口,则无需在任何其他部分中提及它。并且,为了最大限度地保持可用性,请不要重复它们。



-SA
How, how can you possibly have another base class, Shape?! The window created via XAML has the base class Window; and you are trying to add one more base class. Did you know that in .NET there is no multiple inheritance. Remove everything from inheritance list of the other part (partial declaration) of the class.

Only the weak form of multiple inheritance is allowed, for interfaces. Therefore, in each part, you can add any number of interfaces in inheritance list (of course, you would have to implement all of them).

By the way, the practical consequence from the partial declaration rules is: in all parts, inheritance list should be different (except the empty ones). If a base class or interface is mentioned in one of the parts, no need to mention it in any other parts. And, for maximum maintainability, never repeat them.

—SA


这篇关于部分声明不得指定不同的基类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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