Change Data template dynamically

后端 未结 2 692
自闭症患者
自闭症患者 2020-11-29 23:20

I have a item control which is bound to Tasks. Each task has task state. I have defined different data templates for each task state, and also data template selector.

<
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 00:13

    A DataTemplateSelector does not respond to PropertyChange notifications, so it doesn't get re-evaluated when your properties change.

    The alternative I use is DataTriggers that changes the Template based on a property.

    For example, this will draw all TaskModel objects using a ContentControl, and the ContentControl.Template is based on the TaskStatus property of the TaskModel

    
         
     
    
    
         
     
    
    
         
             
                 
             
         
     
    

提交回复
热议问题