作者:zaizaiwaipo | 来源:互联网 | 2023-09-23 14:37
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
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逻辑。