WPF Tree Datatemplate Depending on Type of Item

前端 未结 2 1414
后悔当初
后悔当初 2021-01-22 20:59

I have a MVVM WPF application with a tree containing self referenced data, this data is bound to the tree with a hierarchical converter. (As in example: http://www.telerik.com/h

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-22 21:12

    If you have actual different types, you can specify the type in the HierarchicalDataTemplate using DataType attribute (How do I use the DataType property on a WPF DataTemplate?) and WPF will select the template based on the class.

    If you don't have different types, but will depend on a property or value inside the class, you'll need to specify a DataTemplateSelector (http://tech.pro/tutorial/807/wpf-tutorial-how-to-use-a-datatemplateselector)

提交回复
热议问题