Kevin Fan分享开发经验,记录开发点滴
XAML实例教程系列 - XAML传递参数到值转换类实例
2012-06-28 05:25 by jv9, 508 阅读, 0 评论, 收藏, 编辑继上一篇值类型转换器(Type Converter), 这篇将通过实例代码讲解一个XAML开发小技巧。
在Silverlight应用开发中,经常需要进行值转换,例如从Boolean转换到Windows.Visibility,或者从数字转换到字符。下例中演示如何在XAML中传递参数到值转换类。
定义简单数据成员类:
public class Book
{
public DateTime PublishDate { get; set; }
}
{
public DateTime PublishDate { get; set; }
}
定义值转换类:
public class DateTimeConverter : System.Windows.Data.IValueConverter
{
public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )...
public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )...
}
{
public object Convert( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )...
public object ConvertBack( object value, Type targetType, object parameter, System.Globalization.CultureInfo culture )...
}
在XAML中传递参数到值转换类,
<TextBlock Text="{Binding PublishDate, Converter={StaticResource DateTimeConverter}, ConverterParameter=true}"/>
在CS代码中,传递参数到值转换类,
Book myBook = new Book();
myBook.PublishDate = DateTime.Now;
Binding binding = new Binding( "PublishDate" );
binding.Source = myBook;
binding.Converter = new DateTimeConverter();
binding.ConverterParameter = true;
myBook.PublishDate = DateTime.Now;
Binding binding = new Binding( "PublishDate" );
binding.Source = myBook;
binding.Converter = new DateTimeConverter();
binding.ConverterParameter = true;
XAML实例教程系列:
XAML实例教程系列 - 标记扩展(Markup Extensions)XAML实例教程系列 - 类型转换器(Type Converter)
欢迎大家留言交流,或者加入QQ群交流学习:
22308706(一群) 超级群500人
37891947(二群) 超级群500人
100844510(三群) 高级群200人
32679922(四群) 超级群500人
23413513(五群) 高级群200人
32679955(六群) 超级群500人
88585140(八群) 超级群500人
128043302(九群 企业应用开发推荐群) 高级群200人
101364438(十群) 超级群500人
68435160(十一群 企业应用开发推荐群)超级群500人
第二月 day3 闭包,递归
day4 装饰器
第二月 day1生成器
第一个月 总结
day 16 迭代器
day 15 编码
Docker常用命令
DRF源码刨析
django中使用qiniu作为第三方存储
Copyright © 2011-2022 走看看