我想尝试为我的小应用程序设计MVC模式。
我有一个普通的C#类ViewBase,它继承自UserControl。它是一个单独的.cs文件。
我有多个类想要扩展ViewBase。这些都是实际的UserControl,因此它们有一个带有代码的.cs文件和一个.xaml文件。
但是,C#告诉我,对于这些类,它们的基类“与其他部分声明不同”。
我想做的事情有可能吗?我做错了什么?
请注意,我没有修改我的XAML文件,因此它们仍使用标记。
以下是相关代码:
// This gives the error in question and ViewBase is underlined
// "Base class of LoginView differs from declared in other parts"
public partial class LoginView : ViewBase {
public LoginView(Shell shell, ControllerBase controller) : base(shell, controller) {
InitializeComponent();
}
}
// This one is a single .cs file
public abstract class ViewBase : UserControl {
public Shell Shell { get; set; }
public ControllerBase Controller { get; set; }
protected ViewBase(Shell shell, ControllerBase controller)
{
Shell = shell;
Controller = controller;
}
}