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

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

问题描述

我有一个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设计器无法加载从通用类继承的Form的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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