Something like a template or base DataTemplate which both DataTemplates extend or inherit so I don't have to duplicate XAML.
A:
What about UserControls? Create a base UserControl and then extend the second one?
<DataTemplate>
<local:MyBase />
</DataTemplate>
And extend it like this?
<DataTemplate>
<local:MyBase />
<local:SomeOtherStuff />
</DateTemplate>
rudigrobler
2010-09-08 10:00:26
A:
You can nest DataTemplates. Here an is example
<DataTemplate x:Key="InnerTemplate">
<TextBlock Text="{Binding}" Foreground="Purple" />
</DataTemplate>
<DataTemplate x:Key="OuterTemplate">
<StackPanel>
<TextBlock Text="Header" Foreground="Red" />
<ContentPresenter Content="{Binding}" ContentTemplate="{StaticResource InnerTemplate}" />
</StackPanel>
</DataTemplate>
In this case I just have a List bound to a listbox, and its itemtemplate set to the OuterTemplate template.
<ListBox x:Name="_lbTest" Grid.Row="1" ItemTemplate="{StaticResource OuterTemplate}" ></ListBox>
mdm20
2010-09-08 13:11:56
I actually like the idea of nesting data templates better than pulling out chunks of my data template into a user control. Unfortunately, the chunk I want to share is the outer template so this approach is not possible in my case.
Chry Cheng
2010-09-09 05:30:24