热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

部分声明不得指定不同的基类-Partialdeclarationsofmustnotspecifydifferentbaseclasses

IknowthereisinformationonthisontheinternetbutImhavingproblemstranslatingittomysitu

I know there is information on this on the internet but Im having problems translating it to my situation.

我知道在互联网上有关于此的信息,但我在将其转换为我的情况时遇到了问题。

I have a xaml window and im getting the error: Partial declarations of 'GX3OpenStackupGUIPlugin.GX3OpenStackupGUIPlugin' must not specify different base classes .

我有一个xaml窗口,我得到错误:'GX3OpenStackupGUIPlugin.GX3OpenStackupGUIPlugin'的部分声明不能指定不同的基类。

My code behind is:

我的代码背后是:

public partial class GX3OpenStackupGUIPlugin : GX3ClientPlugin, IGX3PluginInterface
    {

My xaml is:

我的xaml是:


Please could someone advise :)

请有人建议:)

Here is a link to what I have found but am struggling to translate... Partial declarations must not specify different base classes

这是我找到的链接,但我正在努力翻译......部分声明不能指定不同的基类

After doing a little more research I have discovered that if I change my code behind to implement the top level element in my xaml it gets rid of the error. Thats obviously still a problem as my codebehind class needs to implement the interfaces I have designed.

在做了一点研究之后,我发现如果我改变我的代码来实现我的xaml中的顶级元素,它就会摆脱错误。这显然仍然是一个问题,因为我的代码隐藏类需要实现我设计的接口。

4 个解决方案

#2


4  

I got this error when I tried to inherit a TabItem. The .cs looked like:

当我尝试继承TabItem时出现此错误。 .cs看起来像:

public partial class ucTabItemSelectionCriteria : TabItem

The first line of XAML looked like:

XAML的第一行看起来像:

That was the mismatch that would show up when code was generated from the XAML. It was fixed when I change the first 2 lines of XAML to:

这是从XAML生成代码时出现的不匹配。当我将XAML的前两行更改为:

    

Now both are inherited from the TabItem control.

现在两者都继承自TabItem控件。

#3


2  

Partial class declarations mean you can specify code for the same class in 2 different files:

部分类声明意味着您可以在2个不同的文件中指定同一个类的代码:

AOther.cs

public partial class A
{}

A.cs

public partial class A
{}

This error is telling you that the classes define different bases.

此错误告诉您类定义了不同的基础。

AOther.cs

public partial class A : B
{}

A.cs

public partial class A : X
{}

In the example, A can not inherit from B and X in different files. I think it's possible to specify the inheritance chain in XAML but I can't see anything doing this in your posted code.

在示例中,A不能从不同文件中的B和X继承。我认为可以在XAML中指定继承链,但我在发布的代码中看不到任何这样做。

Update

With the modifications to the question in the comment I suggest the following. Rather than looking at inheritance to make your control/window inherit from a GX3ClientPlugin you should look at composition. Essentially this means, place an instance of a GX3ClientPlugin on your form and call through to it. If need be write an interface for the GX3ClientPlugin class, make the form implement it, but for each method just call through to the instance it holds underneath. I think inheritance is the wrong way to go with this problem, as your class has 2 concerns - UI and GX3ClientPlugin logic.

随着评论中对问题的修改,我建议如下。而不是查看继承以使您的控件/窗口继承自GX3ClientPlugin,您应该查看组合。基本上这意味着,在表单上放置一个GX3ClientPlugin实例并调用它。如果需要为GX3ClientPlugin类编写一个接口,请使表单实现它,但是对于每个方法,只需调用它所在的实例。我认为继承是解决这个问题的错误方法,因为你的类有两个问题 - UI和GX3ClientPlugin逻辑。

#4


1  

There are going to be two (or more) parts to that partial class. If you search, you should find another class GX3OpenStackupGUIPlugin, that probably specifies something like Control as the base-type. You are only looking at one part of the file. The other half probably needs to be expanded from under the xaml.

该部分类将有两个(或更多)部分。如果你搜索,你应该找到另一个类GX3OpenStackupGUIPlugin,它可能指定像Control这样的基类型。您只看到文件的一部分。另一半可能需要从xaml下扩展。

The problem is that two files are doing something like this:

问题是两个文件正在做这样的事情:

(file the first)

(档案第一)

public partial class GX3OpenStackupGUIPlugin : GX3ClientPlugin, IGX3PluginInterface {}

(file the second)

(档案第二)

public partial class GX3OpenStackupGUIPlugin : SomethingElse {...}

推荐阅读
author-avatar
zaizaiwaipo
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有