共用方式為


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, add the object to a list of selectable and selected objects in a selection container. 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 information, see Walkthrough: Exposing Properties to the Properties Window.

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.

Add an array of objects to SelectableObjects and SelectedObjects.

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 that has 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.

Private m_someText As String = ""

<Category("My Properties")> _
<Description("Simple Properties")> _
<DisplayName("MyText")> _
Public Property SomeText() As String 
    Get 
        Return m_someText
    End Get 
    Set(ByVal value As String)
        m_someText = value
    End Set 
End Property
private string someText = "";

[Category("My Properties")]
[Description("Simple Properties")]
[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