Share via


Support for the Property Browser

When you select an object in Visual Studio, the public properties of that object appear in the Properties window. To select an object programmatically, you add the object to a list of selectable and selected objects in a selection container. You use the STrackSelection service to notify Visual Studio of the selection.

There can be several lists of selected objects, only one of which is active. Visual Studio chooses the selection list to display in the Properties window depending on the window that has focus and other factors. For more info, see Walkthrough: Exposing Properties to the Properties Window (C#).

Managed Support for the Properties Window

Both managed package framework (MPF) and interop support are provided for creating selection containers, lists, and services from managed code.

MPF provides the SelectionContainer class to create a selection container. Selection containers have two collection properties, SelectableObjects and SelectedObjects. You can also create a selection container by implementing ISelectionContainer.

You add an array of objects to SelectableObjects and SelectedObjects.

You get an ITrackSelection interface from the STrackSelection service, and then call OnSelectChange to notify Visual Studio of the selection. The public properties of the objects you add appear in the Properties window shortly after you call OnSelectChange.

Note

To dispose of a property or object displayed in the Properties window, call OnSelectChange with a null selection container first. After disposing of the property or object, you can change to a selection container with updated SelectableObjects and SelectedObjects lists.

Property Attributes and Layout

The CategoryAttribute, DisplayNameAttribute, and DescriptionAttribute attributes determine the layout, labeling, and description of properties in the Properties window. These attributes determine the category, display name, and description of the option, respectively.

Note

Equivalent attributes, SRCategory, LocDisplayName, and SRDescription, use string resources for localization and are defined in the managed project sample.

Consider the following code fragment:

[Category("My Properties")] 
[Description("Simple Property")] 
[DisplayName("MyText")] 
public string SomeText { 
   get { return someText; } 
   set { someText = value; } 
}

The SomeText property appears in the Properties window as MyText in the category, My Properties. If the property is selected, the description, Simple Property, appears.

See Also

Reference

Properties Window

Other Resources

VSPackage State