码迷,mamicode.com
首页 > 其他好文 > 详细

DataTemplate 以及Template Selector 学习笔记

时间:2016-04-24 21:34:31      阅读:247      评论:0      收藏:0      [点我收藏+]

标签:

1. 内容控件通过ContentTemplate,列表控件通过itemTemplate 来支持模板绑定。例子如下:

模板定义:

xaml:

<DataTemplate x:Key="RadioSelector">
            <Grid  Width="500">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="2*"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding ParamName}"  />
                <RadioButton Grid.Column="1" IsChecked="{Binding ParamValue, Mode=TwoWay}" Content="True" />
                <RadioButton Grid.Column="2"  Content="False" HorizontalAlignment="Right" IsChecked="{Binding ParamValue, Mode=TwoWay, Converter={StaticResource StatusConvert}}"/>
            </Grid>
        </DataTemplate>

 

class:

public class StatusValueConverter : IValueConverter
  {
      public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
      {
          bool status = (bool)value;
          return !status;
      }
      public object ConvertBack(object value, Type targetType, object parameter,CultureInfo culture)
      {
          bool status = (bool)value;
          return !status;
      }
  }

DataTemplate 以及Template Selector 学习笔记

标签:

原文地址:http://www.cnblogs.com/kongshu-612/p/5428123.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!