views:

27

answers:

1

Here's the problem.
Given a large/intricate datatemplate A, which has 3 sections - General, Properties, Misc. Imagine 3 grids for each.
Now I need to reuse the Properties section of the above Datatemplate in another place. Reasons: To avoid redundancy + ensure that further updates to the datatemplate are applied identically to all usages.

So I guess what I am asking for is an ability to slot in a link to a child DataTemplate in a parent Datatemplate. What's the best way to go about this ?

I found one way to do this.. but I'm not sure if its the right way or the best.. Posting it as an answer below so that it can be rated.

+2  A: 

I used a ContentPresenter to slot in a child datatemplate via its ContentTemplate property.

// child
<DataTemplate x:Key="propertiesVMTemplate">
    <toolkit:DataGrid Style= ....  // lots of stuff here
    </toolkit:DataGrid>
</DataTemplate>

// parent
<DataTemplate x:Key="nodeVMTemplate">
    ... general section
        // and the link
        <ContentPresenter Content="{Binding Properties}" ContentTemplate="{StaticResource propertiesVMTemplate}"/>

        ...misc section stuff
</DataTemplate>
Gishu