Reputation: 33
is it possible to use two different DataTemplates in one WPF TreeView?
Maybe the first and second flat with yellow Background and the thirt flat with red Background.
Where is the right place for the distinction - in Code or in XAML?
Thanks for your ideas.
Upvotes: 2
Views: 3424
Reputation: 19885
Different templates are possible in more than one ways...
Templates at various hierarchy levels.
Templates using selector.
One template with multiple data triggers setting various backgrounds.
Upvotes: 3
Reputation: 11051
Sure, if you use HierarchicalDataTemplate
you will see that these also have an ItemTemplate field where you can supply another HierarchicalDataTemplate for the sub children, where you can provide another look for the items. Also you can use implicit DataTemplates, or use an ItemTemplateSelector
. It more or less depends on your actual needs.
I'm not sure, but maybe it is also possible, if you just want to change the color, which can be used with a trigger, to use the AlternationCount property, but i never used it myself.
Upvotes: 0