c# - 使用 WPF 窗口的通用基类

标签 c# wpf generics

这是为什么:

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 >

其中 nsWindowControlsOfAngleSteel 所在的命名空间。

在代码中(可选):

public partial class AnglesteelWindow : WindowControlsOfAngleSteel
{

}

关于c# - 使用 WPF 窗口的通用基类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34006644/

相关文章:

c# - 如何在界面显示进度条时对 COM 对象进行长时间调用?

c# - 我们可以在 WPF 中的 DataGrid 单元格内有一个网格吗?

java - 为什么我的通用实现不起作用? (扩展Comparable<? super T>>)

java - 具有相同类型的静态嵌套类的泛型类

c# - 动态初始化 iset<t>

c# - 南希.ViewEngines.ViewNotFoundException : Unable to locate view 'Index'

c# - 如何在服务器控件中添加 css 引用?

c# - 您可以缓存编译后的代码以针对不同的 Session/hostObject 执行吗?

c# - 如何将 WPF 用户控件创建为 dll,然后在另一个 WPF 应用程序中查看它?

c# - Kinect SDK - 按度数变换角度的旋转