zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    splay
    开车旅行(2012day1T3)
    LCT入门
    最小瓶颈路
    poj 3041 Asteroids
    sql waitfor 延时执行
    [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server 不存在或访问被拒绝
    SQL Server中行列转换
    sql中 with rollup 、with cube、grouping 统计函数用法
    sql 分组后 组内排名
  • 原文地址:https://www.cnblogs.com/itelite/p/4025611.html
Copyright © 2011-2022 走看看