-1

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.

Bobby Tables
  • 2,953
  • 7
  • 29
  • 53
  • 1
    The function you're using is returning a ToolWindowPane. With this object you can maybe do more – realvictorprm Jan 05 '17 at 17:43
  • However, it would be easier if you would provide more source code. In the current state it's not easy to get code working. – realvictorprm Jan 05 '17 at 17:55
  • @ArthurM I would gladly post more code if I knew what would be useful, unfortunately, I'm just fallowing the tutorial from [here](https://msdn.microsoft.com/en-us/library/cc138529.aspx) , which show me how to create a custom tool window, but offers little insight on how to get a reference to an existing one. – Bobby Tables Jan 05 '17 at 18:47
  • The standard way is to use IVsMonitorSelection:GetCurrentSelection but it returns null for the IVsMultiItemSelect argument when used wih objects displayed in the custom WPF property browser... – Simon Mourier Jan 14 '17 at 18:29

2 Answers2

1

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.

Arci
  • 588
  • 7
  • 20
  • Thank you very much for your answer, but unfortunately it doesn't not help, because it would require updating our entire component library which has a few hundred components, this is the main reason I'm looking for a solution by creating a vs extension. – Bobby Tables Jan 17 '17 at 08:51
  • That's the standard way. Are you not able to use some parent control? Few hundred components could have only few forefathers. – Arci Jan 17 '17 at 15:25
0

Can you please check How to enumerate all dependency properties of control?

I think this will help you for what you are looking for...

Regards,

Community
  • 1
  • 1
Nirav Raval
  • 117
  • 1
  • 6
  • Hello, I know how to enumerate the dependency properties of a control, the thing is that I don't want to create the content of the Properties window for WPF from scratch I just want to hide elements from it using a VS extension. – Bobby Tables Jan 17 '17 at 11:50