I have two HierarchicalDataTemplate
s that are identical, except for the ConverterParameter
used for the ItemsSource
property:
<HierarchicalDataTemplate x:Key ="Template1"
ItemsSource="{Binding Converter ={StaticResource DemoConverter}, ConverterParameter='One'}">
...
</HierarchicalDataTemplate>
<HierarchicalDataTemplate x:Key ="Template2"
ItemsSource="{Binding Converter ={StaticResource DemoConverter}, ConverterParameter='Two'}">
...
</HierarchicalDataTemplate>
How can I avoid the redundancy (replaced above by ...
)? I would like to have only one template that I can pass the (static) ConverterParameter
to. Something like this (with PARAMETER placeholder):
<HierarchicalDataTemplate x:Key ="Template"
ItemsSource="{Binding Converter ={StaticResource DemoConverter}, ConverterParameter={PARAMETER}">
...
</HierarchicalDataTemplate>
And, in the "consuming" code I would write something like (with another PARAMETER placeholder):
<TreeView ItemTemplate="{StaticResource ProjectTreeEditItem, PARAMETER=One}" ...></TreeView>
or
<TreeView ItemTemplate="{StaticResource ProjectTreeEditItem, PARAMETER=Two}" ...></TreeView>
How can this be achieved? A suitable (although sub-optimal) solution would be to have two "wrapper" templates that reference one common template (setting the parameter from there, if setting the parameter as part of the ItemTemplate
definition is the problem), but I wouldn't know how to do that either :o/