I have a ResourceDictionary that lists different styles used in my wpf application.
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate x:Key="TemplateA">
<Some A specific definitions />
<StackPanel>
<!-- Same content as other templates -->
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="TemplateB">
<Some B specific definitions />
<StackPanel>
<!-- Same content as other templates -->
</StackPanel>
</DataTemplate>
etc...
Now how do I share the same StackPanel content across TemplateA and TemplateB in the same ResourceDictionary?
I apologize if Im missing something simple as this is my first pass learning WPF. Thanks
Create a third DataTemplate and use a ContentPresenter
to show that:
<DataTemplate x:Key="SharedPart">
<StackPanel>
<!-- Same content as other templates -->
</StackPanel>
</DataTemplate>
<DataTemplate x:Key="TemplateA">
<Some A specific definitions />
<ContentPresenter Content="{Binding}"
ContentTemplate="{StaticResource SharedPart}"/>
</DataTemplate>
<DataTemplate x:Key="TemplateB">
<Some B specific definitions />
<ContentPresenter Content="{Binding}"
ContentTemplate="{StaticResource SharedPart}"/>
</DataTemplate>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With