ItemsControl with multiple DataTemplates for a viewmodel

前端 未结 4 1501
陌清茗
陌清茗 2020-11-29 04:59

is it possible to bind an itemscontrol with canvas as template to multiple DataTemplates?

I have 2 collections and depending on the type I would like to display a di

4条回答
  •  臣服心动
    2020-11-29 05:20

    You could have ObservableCollection in your ViewModel and bind the ItemsControl's Source to this collection.

    Then, to get a different look for different types of data, you could two DataTemplates without x:Key, but with properly set DataType in your Resources. The ItemsControl will then automatically select the appropriate DataTemplate for your item.

    提交回复
    热议问题