Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ContentPresenter DataTemplate

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?

like image 537
thumbmunkeys Avatar asked Apr 11 '11 09:04

thumbmunkeys


2 Answers

Should be something like:

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

Although I wouldn't define a Template on a contentpresenter, I will select the correct template based on the type anyway.

like image 155
Martin Moser Avatar answered Oct 11 '22 14:10

Martin Moser


You just need to reference the defined resource:

<ContentPresenter Content="{Binding X}" ContentTemplate="{StaticResource myTemplate}"/>
like image 41
Pavlo Glazkov Avatar answered Oct 11 '22 13:10

Pavlo Glazkov