2011-03-23 54 views
6

問題:當基類正在實現另一個程序集的接口時,Windows窗體設計器不適用於繼承的用戶控件。VS2010:如何在使用繼承用戶控件時避免Windows窗體設計器出現問題?

平臺:VS 2010 SP1,.NET 4.0框架

錯誤:

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: MyControl --- The base class 'MyBaseControlLib.MyBaseControl' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.

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 Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.DeferredLoadHandler.Microsoft.VisualStudio.TextManager.Interop.IVsTextBufferDataEvents.OnLoadCompleted(Int32 fReload)

我有3個類庫項目的解決方案:

MyInterfaceLib:

namespace MyInterfaceLib 
{ 
    public interface IMyInterface 
    { 
     void Foo(); 
    } 
} 

MyBaseControlLib:

namespace MyBaseControlLib 
{ 
    using System.Windows.Forms; 
    using MyInterfaceLib; 

    public partial class MyBaseControl : UserControl, IMyInterface 
    { 
     public MyBaseControl() 
     { 
      InitializeComponent(); 
     } 

     public void Foo() 
     { 
     } 
    } 
} 

MyDerivedLib:

namespace MyDerivedControlLib 
{ 
    using MyBaseControlLib; 

    public partial class MyControl : MyBaseControl 
    { 
     public MyControl() 
     { 
      InitializeComponent(); 
     } 
    } 
} 

雖然設計師作品的MyBaseControl它不會爲MyControl工作。 如果MyBaseControl沒有實現IMyInterface,那麼設計器也適用於MyControl。

任何想法?

感謝, 羅伯特

+0

是不是在關鍵就在這「基類的MyBaseControlLib.MyBaseControl「無法加載。確保組件已經提到,所有項目已建成。」 ..? – 2012-10-08 13:35:25

+0

在我的(有限)體驗中,VS在用戶控件和自定義控件方面存在很多問題,這些問題與您使用的解決方案相同。當我降低「便利的野心水平」並接受這一點時,我總是遇到更少的問題,併爲控件創建單獨的解決方案。然後,我只從其他項目引用DLL,如果我自己修改了控件,則使用「重建」而不是「構建」。 – 2012-10-08 13:39:56

回答

2

我們有同樣的問題。我們通過創建一個由MyControl類繼承的MyControlDesign類來使用workarround。

public partial class MyControl : MyControlDesign { 
    public MyControl() 
    { 
     InitializeComponent(); 
    } 
} 

public partial class MyControlDesign : MyBaseControl 
{ 
    public MyControlDesign():base() 
    { 
    } 
}