Change Data template dynamically

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

时间: 2024-08-08 01:14:50

Change Data template dynamically的相关文章

SSIS CDC(Change Data Capture)组件在数据库中启用报错。 The error returned was 14234: &#39;The specified &#39;@server&#39; is invalid

昨天实验CDC,在数据库中执行以下语句的时候出错. EXEC sys.sp_cdc_enable_table @source_schema = N'stg', @source_name = N'CDCSalesOrderHeader', @role_name = N'cdc_role', @supports_net_changes = 1; Msg 22832, Level 16, State 1, Procedure sp_cdc_enable_table_internal, Line 623

SQL Server审计功能入门:CDC(Change Data Capture)

介绍 SQL Server 2008引入了CDC(Change Data Capture),它能记录: 1. 哪些数据行发生了改变 2. 数据行变更的历史记录,而不仅仅是最终值. 跟CT(Change Tracking)相比,它通过作业实现异步变更跟踪(像事务复制),而CT是同步实现的.因此它对性能的影响较轻并且不会影响事务. 典型应用是在提取.传输和加载数据到其它数据源,就像图中的数据仓库. 实现 微软建议CDC结合快照快照隔离级别使用,可以避免读取变更数据与变更数据写入时的读写阻塞. 需要注

CC2540/CC2541 : Change Scan Response Data( SRP) dynamically

How to change the SRP data is a very imperative for most bluetooth low energy use case. But in official Texas Instruments(TI) example code, there is no demonstration  for this purpose. In here, I note how to reach the goal. In the TI forum , it sai p

[WPF系列-数据邦定之DataTemplate 根据对象属性切换模板

  引言 书接上回[WPF系列-数据邦定之DataTemplate],本篇介绍如何根据属性切换模板(DataTemplate)   切换模板的两种方式:   使用DataTemplateSelector来切换模板 使用DataTrigger来实现模板切换. 使用Style来是实现模板切换   A DataTemplateSelector does not respond to PropertyChange notifications, so it doesn't get re-evaluated

[ExtJs] ExtJs4.2 数据模型Ext.data.Model学习

Model代表应用程序管理的一些对象.例如,我们可能会为 我们想在系统中建模的现实世界中的一些物体像使用者.产品和汽车等定义一个Model.这些Model在 Ext.ModelManager中注册,被Ext.data.Store使用, 而这些Ext.data.Store又被许多 Ext中许多与数据绑定的组件使用. 直接上代码: <%-- Created by IntelliJ IDEA. User: Administrator Date: 2015/12/13 0013 Time: 08:51

[转]Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10)

本文转自:http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application Creating an Entity Framework Data Model for an ASP.NET MVC Application (1 of 10) By      

Lock-Free Data Structures

By Andrei Alexandrescu, October 01, 2004 Post a Comment Lock-free data structures guarantee the progress of at least one thread when executing mutlithreaded procedures, thereby helping you avoid deadlock. Andrei Alexandrescu is a graduate student in

[转]Table-Driven and Data Driven Programming

What is Table-Driven and Data-Driven Programming? Data/Table-Driven programming is the technique of factoring repetitious programming constructs into data and a transformation pattern. This new data is often referred to by purists as meta-data when u

.NET开发微信小程序-Template模块开发

1.添加一个文件目录,里面放模板信息 例:我在根目录添加一个文件夹:template 然后在这个文件夹下面添加相应的页面.比如我添加一个promodel.wxml文件.主要是放商品相关的模块信息(注:模板文件也是用的.wxml) <template name="proname"> <view class="myTempleta"> {{data.title}} </view>> </template>> 注