ContentPresenter DataTemplate

thumbmunkeys picture thumbmunkeys · Apr 11, 2011 · Viewed 16.7k times · Source

I have a DataTemplate:

<DataTemplate x:Key="myTemplate">
    ...
</DataTemplate>

I want to use it as the ContentTemplate of a ContentPresenter:

<ContentPresenter Content="{Binding X}">
    <ContentPresenter.ContentTemplate >
        <!-- ????? what goes here ????-->
    </ContentPresenter.ContentTemplate>
</ContentPresenter>

How can I use the predefined DataTemplate in my ContentPresenter?

Answer

Pavlo Glazkov picture Pavlo Glazkov · Apr 11, 2011

You just need to reference the defined resource:

<ContentPresenter Content="{Binding X}" ContentTemplate="{StaticResource myTemplate}"/>