6

I'm using Visual Studio 2010 and WPF.

I'm creating a new Control that inherits from ContentControl and I wanna hide the Content property so it will be invisible in the Properties window at design time.

I tried with

[Browsable(false)]

like we do in WinForms but it doesn't work.

Any idea about how to solve this?

Thank you.

Dan J
  • 16,319
  • 7
  • 50
  • 82
Michelle
  • 601
  • 1
  • 8
  • 17

1 Answers1

6

Michelle,

Your property needs to be set to public:

[Browsable(false)]
public new object Content
{
    get { return base.Content; }
    set { base.Content = value; }
}

Once you set it to public, it will hide from the properties window.

With Private:

enter image description here

With Public:

enter image description here

Thanks

CodeLikeBeaker
  • 20,682
  • 14
  • 79
  • 108
  • Hi @Jason thank you for your help. Now it works. But now I've another problem... I've declared it in a base class when I create a new class inheriting from that base class then the Content property appear again in the Properties window. However if I move the Content property re-declaration to the new class it disappears from the Properties Window. Why is this happening? – Michelle Nov 10 '11 at 12:29
  • @Michelle not sure if I'm following, but I was able to create a "BaseControl" class which inherited ContentControl. Then my "MyControl" inherited "BaseControl". If i put the public new object Content in either class, it remains hidden on the form. – CodeLikeBeaker Nov 10 '11 at 15:46
  • if you don't rewrite the property again in the "MyControl" then it appears in the Property window. However when I do the same in Forms I don't have to rewrite the properties in the derived classes. Why is this happening in WPF? – Michelle Nov 23 '11 at 20:45
  • wait, so in order to protect a dp from edit via the designer we have to expose it as public? This is counterproductive, surely? – IAmJersh Apr 08 '20 at 11:56
  • @TheHitchenator TBH, I answered this 9 years ago. I no longer use WPF, so I can't really provide a solid answer to your question. I do apologize, but yeah, it does seem counterproductive. – CodeLikeBeaker Apr 24 '20 at 16:10