In WPF and Silverlight there is an element called ContentPresenter, that is often used inside control templates, as well as inside the root application markup. The concept of ContentPresenter is quite simple – it is a placeholder for any XAML content and it can be used to insert content at runtime.
What I personally find it useful for is dynamic user interface, where there is no need to define a static UI structure at design time, but at runtime there should be some components that are either defined in the application XAML or in an external resource.
A content presenter is used via the ContentPresenter element: <ContentPresenter></ContentPresenter>. The content inside this element can be partially (or completely, although its value is lost in this case) defined inside the <ContentPresenter.Content></ContentPresenter.Content> element.
If you consider using the ContentPresenter element by defining the content from scratch, there is no need to include the Content element in the base XAML – it cannot be empty and running it so will cause an exception to be thrown. Once the content is set at runtime, the proper tag will be added automatically.
Let’s take a look at an example
<Grid>
<ContentPresenter Name="MyContent">
</ContentPresenter>
</Grid>
No comments:
Post a Comment