1. Attached Property bound to task state. Any change will dynamically set data template.
2. Visual State Manager

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

<DataTemplate x:Key="OpenTaskTemplate" TargetType="{x:Type local:TaskModel}">
<TextBlock Text="I'm an Open Task" />
</DataTemplate> <DataTemplate x:Key="ClosedTaskTemplate" TargetType="{x:Type local:TaskModel}">
<TextBlock Text="I'm a Closed Task" />
</DataTemplate> <DataTemplate DataType="{x:Type local:TaskModel}">
<ContentControl Content="{Binding }">
<ContentControl.Style>
<Style TargetType="{x:Type ContentControl}"> <!-- Default Template -->
<Setter Property="ContentTemplate" Value="{StaticResource OpenTaskTemplate}" /> <!-- Triggers to change Template -->
<Style.Triggers>
<DataTrigger Binding="{Binding TaskStatus}" Value="Closed">
<Setter Property="ContentTemplate" Value="{StaticResource ClosedTaskTemplate}" />
</DataTrigger>
</Style.Triggers>
</Style>
</ContentControl.Style>
</ContentControl>
</DataTemplate>

From: https://stackoverflow.com/questions/13136816/change-data-template-dynamically

最新文章

  1. jquery 自定义click事件执行多次
  2. POJ2763 Housewife Wind
  3. [正则表达式]PCRE反向分组引用
  4. Android UiAutomator快速调试
  5. hive中分号问题
  6. IO流03--毕向东JAVA基础教程视频学习笔记
  7. centos6.5yum方式升级内核
  8. [转] 你是as3老鸟吗?但是有些你可能目前都不知道的东西
  9. Ehcache(2.9.x) - Configuration Guide, Configuring Cache
  10. strings和nm命令
  11. Visual Studio 使用及调试必知必会
  12. 零基础2018如何系统地学习python?
  13. 面试题-一个for循环输出一个棱形
  14. SQL Server 2017 新功能分享
  15. cookie路径问题
  16. vue中 左侧导航条 多个toggleClass
  17. C#设计模式 ---- 总结汇总
  18. MessageFormat格式化数字
  19. linux cpu过高原因及代码定位
  20. Menubar

热门文章

  1. [Unity3D]Unity3D游戏开发之跑酷游戏项目解说
  2. 关于android fragment 某些使用记录
  3. Atitit Loading 动画效果
  4. Atitit 图像处理 halcon类库的使用 &#160;范例边缘检测 attilax总结
  5. 深入理解Linux内核-进程地址空间
  6. vue.js $refs和$emit 父子组件交互
  7. sessionStorage 、localStorage、cookie
  8. mysql_secure_installation
  9. MediaType是application/x-www-form-urlencoded的接口测试方法
  10. IOS开发之xib解决自定义CollectionCell问题