Visual Studio 2008 Winform 设计器无法加载从泛型类继承的表单 [英] Visual Studio 2008 Winform designer fails to load Form which inherits from generic class

查看:9
本文介绍了Visual Studio 2008 Winform 设计器无法加载从泛型类继承的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 winforms 项目,我在程序集 A 上创建了一个类,它继承自 System.Windows.Forms.Form 作为各种表单的基类在我的项目中,基类类似于:

i have a winforms project, and i created a class on assembly A that inherits from System.Windows.Forms.Form to serve as a base class for various forms on my project, the base class is something like:

public partial class DataForm<T> : Form where T : class
{

    T currentRecord;

    protected T CurrentRecord
    {
        get
        {
            return currentRecord;
        }
        set
        {
            currentRecord = value;
            CurrentRecordChanged();
        }
    }
}

现在,当我在从我的 DataForm 继承的程序集 B 上创建表单时,设计器不会加载,但如果我编译它,应用程序运行良好.

Now, when i create a form on assembly B that inherits from my DataForm the designer won't load, but if i compile it the app runs fine.

表格如下:

public partial class SomeTableWindow : DataForm<SomeTable>
{
    public SomeTableWindow ()
    {
        InitializeComponent();
    }
}

我得到的错误是:

The designer could not be shown for this file because none of the classes within it can be designed. 
The designer inspected the following classes in the file: CultivosWindow --- The base
class 'TripleH.Erp.Controls.DataForm' could not be loaded. Ensure the assembly has 
been referenced and that all projects have been built.    


Instances of this error (1)  

1.   Hide Call Stack 

at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)  

这是设计师的错误吗?我做错了什么吗?有什么解决方法吗?

Is this a bug on the designer?, Am I doing something wrong? Is there some workaround this?

感谢您的帮助

推荐答案

这是一个已知的限制.基本上,您可以通过声明从泛型类继承的另一个类来解决此问题.

It's a known limitation. Basically you can work around this by declaring another class that inherits from the generic class.

例如:

class Generic<T> : UserControl
{
}

然后

class GenericInt : Generic<int> { }

然后使用 GenericInt 而不是 Generic.我知道很糟糕.

then use GenericInt instead of Generic. SUcks I know.

这篇关于Visual Studio 2008 Winform 设计器无法加载从泛型类继承的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆