2

次のようなデザインタイム サポートを備えたカスタム ユーザー コントロールを作成しました。

プロジェクト/アセンブリ「MyUserControl」

  • MyUserControl.cs
  • MyUserControlDesigner.cs

コードは次のようになります。

namespace MyUserControl
{
  [Designer("MyUserControl.Design.MyUserControlDesigner, MyUserControl", typeof(IDesigner))]
  public class MyUserControl : Control
  {
    // Some stuff here
  }
}

namespace MyUserControl.Design
{
  public class MyUserControlDesigner : ControlDesigner
  {
    // Some other stuff here
  }
}

これら 2 つのクラスが同じアセンブリにある限り、すべて正常に動作します。VS2012 には、すべてのデザイナー オプションが表示されます。しかし、明らかな理由 (System.Design などへの参照) から、デザイナー コードを MyUserControl アセンブリではなく、MyUserControl.Design に配置したいと考えています。だから私は同じソリューションで 2 番目のプロジェクトを作成します。

プロジェクト/アセンブリ「MyUserControl」

  • MyUserControl.cs

プロジェクト/アセンブリ「MyUserControl.Design」

  • MyUserControlDesigner.cs

コードは次のようになります。

namespace MyUserControl
{
  [Designer("MyUserControl.Design.MyUserControlDesigner, MyUserControl.Design", typeof(IDesigner))]
  public class MyUserControl : Control
  {
    // Some stuff here
  }
}

これを使用すると、デザイナーがまったく見つかりません。VS2012 はインラインで選択可能なコンポーネントを表示しませんが、デザイナーがアタッチされていないコンポーネントのようです。

VS2012 がそれを見つけるためにデザイナー アセンブリを GAC に追加する必要がありますか、それともここで何が問題なのですか?

編集: MyUserControl.Design への参照を WindowsFormsApplication1 に追加すると、すべて正常に動作しますが、これはまさにあなたが望んでいないことです...

4

2 に答える 2

0

MyUserControlDesignerパブリッククラスを作成する必要があります。

于 2012-09-04T13:49:14.980 に答える
0

私はまったく同じ問題に遭遇しました。次の方法でデザイナークラスを指定した場合にのみ、機能し始めました。

namespace MyUserControl
{
  [Designer("MyUserControl.Design.MyUserControlDesigner, MyUserControl.Design,  Version=1.0.0.0, Culture=neutral, PublicKeyToken=8bc98ae14acadc09", typeof(IDesigner))]
  public class MyUserControl : Control
  {
    // Some stuff here
  }
}
于 2014-05-22T06:14:21.440 に答える