【问题标题】:Visual Studio 2008 Winform designer fails to load Form which inherits from generic classVisual Studio 2008 Winform 设计器无法加载从泛型类继承的表单
【发布时间】:2011-01-04 07:48:23
【问题描述】:

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

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

    T currentRecord;

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

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

表格如下:

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)  

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

感谢您的帮助

【问题讨论】:

    标签: winforms visual-studio-2008 designer


    【解决方案1】:

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

    例如:

    class Generic<T> : UserControl
    {
    }
    

    然后

    class GenericInt : Generic<int> { }
    

    然后使用 GenericInt 代替 Generic。我知道很烂。

    【讨论】:

    • 我可以确认此解决方法有效。无论您将中间类(例如 GenericInt)放在程序集 A 还是程序集 B 中,它都有效。
    猜你喜欢
    • 2011-01-12
    • 2012-07-17
    • 1970-01-01
    • 2014-05-23
    • 2011-01-14
    • 2011-10-16
    • 1970-01-01
    • 2019-07-11
    相关资源
    最近更新 更多