这是为什么:
public abstract class WindowControls<T> : Window
不可能。我似乎无法弄清楚。
public partial class AnglesteelWindow : WindowControls<AngleSteel> {
private UCListView uc;
public AnglesteelWindow() {
InitializeComponent();
uc = new UCListView();
uc.SubmitClick += new EventHandler(ButtonPressed);
this.uc.grid.PreviewMouseLeftButtonUp +=
new System.Windows.Input.MouseButtonEventHandler(
this.MousePressed14<AngleSteel>);
stkTest.Children.Add(uc);
uc.amountLabel.Content = "Milimeter";
uc.grid.ItemsSource = DatabaseLogic.MaterialTable("Anglesteel").DefaultView;
base.Material(uc, "Anglesteel");
}
}
我知道泛型是如何工作的,但不知道为什么不能让我的 AnglesteelWindow 从 WindowControls 派生。 它给我的错误如下:
Base class of 'Name of the solution' differs from declared in other parts.
当我查看所谓的其他部分时,如下:
public partial class AnglesteelWindow :
WindowControls<AngleSteel> System.Windows.Markup.IComponentConnector {
这是在 AnglesteelWindow.g.i.cs 文件中制作的。如果我从那里删除它,那根本没有区别。
最佳答案
添加@MichaelMairegger 答案,您可以通过创建另一个继承泛型类的非泛型类来实现您的目标,如下所示:
public abstract class WindowControlsOfAngleSteel : WindowControls<AngleSteel>
{
}
并让你的窗口类继承它,如下所示:
来自 XAML:
<ns:WindowControlsOfAngleSteel >
</ns:WindowControlsOfAngleSteel >
其中 ns
是 WindowControlsOfAngleSteel
所在的命名空间。
在代码中(可选):
public partial class AnglesteelWindow : WindowControlsOfAngleSteel
{
}
关于c# - 使用 WPF 窗口的通用基类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34006644/