Different DataTemplates in one TreeView?

淺唱寂寞╮ 提交于 2019-12-11 05:08:23

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/7568597/different-datatemplates-in-one-treeview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!