Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to get access to the properties shown by the properties window when a WPF control is selected.

The problem is that although I've managed to add my own content in the properties window, I have not found a way to obtain a reference to the one used by the WPF designer to display control properties.

private IVsWindowFrame _frame;
...

if(_frame == null) {
    var shell = parent.GetVsService(typeof(SVsUIShell)) as IVsUIShell;
    if(shell != null) {
        var guidPropertyBrowser = new Guid(ToolWindowGuids.PropertyBrowser);
        shell.FindToolWindow(
            (uint) __VSFINDTOOLWIN.FTW_fFindFirst, ref guidPropertyBrowser, out _frame
        );
    }
}

As you can see I already have a reference to the Properties Window but unfortunately I have no idea how to get the properties listed.

In case it's relevant the reason I'm trying to do this is because I want to remove(or hide) some properties shown for the WPF controls in the designer.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
221 views
Welcome To Ask or Share your Answers For Others

1 Answer

Design-time support for WPF controls is based on public properties and attributes. Any public property of control is shown in properties window, but you may change visibility by attributes. There is a simple trick for hide existing property. You must define new property vith same name and add attributes. Is property is defined as virtual you could simply override but you could use keyword new.

Sample code:

public partial class MyUserControl : UserControl
{
    public MyUserControl()
    {
        InitializeComponent();
    }

    [System.ComponentModel.Browsable(false)]
    public new Brush Background
    {
        get { return base.Background; }
        set { base.Background = value; }
    }
}

Design-Time Attributes and Inheritance

When you derive a component or control from a base component that has design-time attributes, your component inherits the design-time functionality of the base class. If the base functionality is adequate for your purposes, you do not have to reapply the attributes. However, you can override attributes of the same type or apply additional attributes to the derived component. The following code fragment shows a custom control that overrides the Text property inherited from Control by overriding the BrowsableAttribute attribute applied in the base class.

See MSDN, you have to use BrowsableAttribute. Base concept is for WinFors and WebForms, but WPF controls have the same.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...