delete
delete

Reputation:

Why are certain control properties shown in the Visual Studio designer, and others not?

Take my navigationItem usercontrol:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Uboldi.Helpers;

namespace Uboldi
{
    public partial class NavigationItem : UserControl
    {
        public bool IsSelected { get; set; }
        public string Text { get; set; }

        public NavigationItem()
        {
            InitializeComponent();
            RefreshDisplay();
        }

        private void RefreshDisplay()
        {
            if (IsSelected)
                this.BackColor = CustomizationHelper.GetSecondaryColor();
            else
                this.BackColor = CustomizationHelper.GetPrimaryColor();            
        }
    }
}

In Visual Studio I can see the IsSelected property, but not the Text property. enter image description here

Any reason why?

Upvotes: 2

Views: 2248

Answers (2)

Hans Passant
Hans Passant

Reputation: 942518

The Text property is inherited from UserControl. Where it is hidden, a user control has no meaningful way of of showing text. You have to inherit it again and turn all the attributes off that make it hidden. Like this:

    [Browsable(true)]
    [EditorBrowsable(EditorBrowsableState.Always)]
    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
    [Bindable(true)]
    public override string Text {
        get { return base.Text; }
        set { base.Text = value; }
    }

Upvotes: 3

Josh Smeaton
Josh Smeaton

Reputation: 48730

You need to mark the properties you want visible in the design time properties list with a BrowsableAttribute.

[Browsable(true)]
public bool Text { get; set; } 

At a guess, the IsSelected property was inherited, and had this attribute set. I'm probably off, because I think the compiler would warn you that you were shadowing an inherited property if this was the case.

Upvotes: 1

Related Questions