简体   繁体   English

视觉继承,设计时支持扩展自定义控件

[英]Visual Inheritance, Design-time support for extended custom controls

I'm extending my own custom control, which extends the UserControl class. 我正在扩展自己的自定义控件,该控件扩展了UserControl类。

I can see all the elements fine in the extending class' designer, but all the properties of the extended custom control appear disabled and when selecting its element with the mouse a "locked" icon appears. 我可以在扩展类的设计器中看到所有元素都很好,但是扩展自定义控件的所有属性都显示为禁用,并且当用鼠标选择其元素时,将出现“锁定”图标。

How can I fix that? 我该如何解决? I would like to be able to modify these properties from the designer. 我希望能够从设计器修改这些属性。

EDIT: Definition of the custom control, which extends from UserControl. 编辑:自UserControl扩展的自定义控件的定义。

namespace Wizard
{
    [Designer(typeof(Wizard.StepDesigner))]
    [DefaultProperty("TitlePanel, NavigationPanel")]
    public partial class Step : UserControl
    {
         public Step()
         {
            InitializeComponent();
         }

         [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
         public Title TitlePanel
         {
              get
              {
                    return this.title1;
              }
              set
              {
                   this.title1 = value;
              }
          }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Panel ContentPanel
        {
            get
            {
                 return this.contentPanel;
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public Navigation NavigationPanel
        { 
             get
             {
                 return this.navigation1;
             }
         }
     }

     internal class StepDesigner : ParentControlDesigner
     {
         public override void Initialize(System.ComponentModel.IComponent component)
         {
            base.Initialize(component);

            if (this.Control is Step)
            {
                 Step control = (Step)this.Control;
                 this.EnableDesignMode(control.TitlePanel, "TitlePanel");
                 this.EnableDesignMode(control.ContentPanel, "ContentPanel");
                 this.EnableDesignMode(control.NavigationPanel, "NavigationPanel");
             }
         }  
     }
 }

正如我在评论中已经指出的那样,属性的修饰符都被设置为私有,并将其更改为保护,并且重建解决方案解决了“问题”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM