harry
harry

Reputation: 33

Different DataTemplates in one TreeView?

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

Answers (2)

Vinit Sankhe
Vinit Sankhe

Reputation: 19885

Different templates are possible in more than one ways...

  1. Templates at various hierarchy levels.

  2. Templates using selector.

  3. One template with multiple data triggers setting various backgrounds.

Upvotes: 3

dowhilefor
dowhilefor

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

Related Questions