Search code examples
wpfsilverlightuser-interfacecontentpresenter

Why do I need ContentPresenter in SilverLight?


If I can replace it with a single TextBox (like on a button), or I can add media element directly to Grid (whatever)...

What is ContentPresenter for? Is there some advantages?


Solution

  • You don't always need a ContentPresenter. It acts as a placeholder that will effectively host any content that you assign to its Content attribute. If you have an area on a given control/page that can hold dynamic content of an indeterminate type, a ContentPresenter is an effective way to hold the space.

    It's also used quite a bit with templating, custom controls, etc. Odds are you won't actually use it until you start getting into some fairly advanced stuff.

    One kind of cool thing you can do is have the Content attribute of the ContentPresenter bound to a DependencyProperty of type UserControl, and then if you set that DependencyProperty equal to any UserControl (like one that you new up in a ViewModel or something), it'll show up in that spot.