2010-01-12 32 views
12

我有一個winforms項目,我創建了一個程序集類ASystem.Windows.Forms.Form繼承作爲我的項目上的各種形式的基類,基類是一樣的東西:Visual Studio 2008 Winform設計器無法加載從通用類繼承的窗體

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

    T currentRecord; 

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

現在,當我創建裝配形式,從我的DataForm設計師將不會加載繼承,但如果我編譯它的應用程序運行正常。

的形式如下:

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) 

這是對設計師的錯誤?難道我做錯了什麼?有沒有一些解決方法呢?

感謝您的幫助

回答

16

這是一個已知的限制。基本上你可以通過聲明從泛型類繼承的另一個類來解決這個問題。

例如:

class Generic<T> : UserControl 
{ 
} 

然後

class GenericInt : Generic<int> { } 

然後用GenericInt而不是通用。蘇克斯我知道。

+0

非常感謝你,你是對的。 – albertein

+0

我可以證實此解決方法可行。無論是將中間類(例如GenericInt)放入程序集** A **還是程序集** B **中,它都可以工作。 –

相關問題