WinUserControl in VS2010 - properties are not displayed in the designer

I have a problem with (I suppose) my Visual Studio 2010 Express environment: when I create my own UserControl, in the Properties grid, I don’t see the public properties of this control. They are, however, visible in the project, citing this control.
Since this is an Express Edition, I create a new empty project and then add a new UserControl to it.
Then for the test I will put the following code:

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; namespace Project1 { public partial class UserControl1 : UserControl { private int myNumber; [Browsable(true)] public int MyNumber { get { return myNumber; } set { myNumber = value; } } public UserControl1() { InitializeComponent(); } } } 

In VS 2008, as I recall, it must be enogh to show the MyNumber property in the property grid even without the [Browsable(true)] attribute. In VS 2010, however, when I double-click UserControl1.cs in Solution Explorer and look in the properties, I do not see MyNumber.
When I reference and use this control in another project, I have access to its properties.

I tried reinstalling the VS 2010 environment, including SP1, but without success. You do not know what could be wrong?

By the way, none of these attributes work:

 [Browsable(true)] [EditorBrowsable(EditorBrowsableState.Always)] [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] [Bindable(true)] 

Yours faithfully,
Marcin

+4
source share
3 answers

I consider this to be the normal behavior of VS2010 and suggest it by design. For me, this is the 2010 Ultimate. When you put UserControl1 on the form, you will see its user properties.

My assumption is that when you design the control, there is no instance of your control yet (it may not have even been compiled). You are viewing an instance of UserControl . When you compile your control and then add it to the form, the designer creates an instance of your control, so its properties can be seen and processed.

+7
source

I have not used the [Browsable] tag before. However, the following is an example of what I use in one of my projects.

 [Description("The length used to display the dimensions")] [Category("Custom")] public double DisplayLength { get; set; } 

I assume you need to add a category.

0
source

This will not work due to the way VS handles ascx'es in Designer. See this great answer to SO for more details.

If the answer is not what you expected, you can still transfer .ascx'es to the User Control library, as I described in my blog .

If I had a choice, I would start using all my ascx code as Web server User Controls .

0
source

All Articles