【问题标题】:How to move custom IDesigner to separate assembly in the same solution?如何将自定义 IDesigner 移动到同一解决方案中的单独程序集?
【发布时间】:2012-08-28 22:03:43
【问题描述】:

我创建了一个具有设计时支持的自定义用户控件,如下所示:

项目/程序集“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
  }
}

只要这两个类在同一个程序集中,一切正常。 VS2012 显示了我所有的设计器选项。但由于明显的原因(对 System.Design 和其他的引用),我不想在 MyUserControl 程序集中包含设计器代码,而是在 MyUserControl.Design 中。所以我在同一个解决方案中创建了第二个项目:

项目/程序集“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 不显示组件内联可选,而是显示没有附加设计器的组件。

我是否必须将我的设计器程序集添加到 GAC 才能让 VS2012 找到它,或者这里有什么问题?

编辑:向 WindowsFormsApplication1 添加对 MyUserControl.Design 的引用时一切正常,但这正是您不想要的......

【问题讨论】:

    标签: c# winforms windows-forms-designer


    【解决方案1】:

    您需要将MyUserControlDesigner 设为公共课程。

    【讨论】:

    • 我在上面的代码中解决了这个问题。在我的真实代码中,这两个类肯定都是公共类。
    • 恐怕我还没找到解决办法。
    【解决方案2】:

    我遇到了完全相同的问题。只有当我通过以下方式指定设计器类时,它才开始为我工作。

    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
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-02-26
      • 2013-05-03
      • 1970-01-01
      • 2010-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多