two itemtemplates for one listbox

后端 未结 2 419
孤城傲影
孤城傲影 2020-12-23 11:33

I\'ve got a class FruitViewModel. It describes ViewModels for ListBox items.


         


        
2条回答
  •  别那么骄傲
    2020-12-23 12:01

    On the ListView in XAML you can declare an ItemTemplateSelector. The value for this will come from a static resource or similar.

    The implementation of your template selector should implement DataTemplateSelector and will basically contain the 'if' statement that chooses the correct DataTemplate based on the bound item's type. It will likely find the DataTemplate from the passed in container's resources (probably using the FindResource function).

    Edit: Good link perhaps? http://www.switchonthecode.com/tutorials/wpf-tutorial-how-to-use-a-datatemplateselector Dead link.

提交回复
热议问题