设为首页 加入收藏

TOP

wpf datagrid field to image converter 字段 图片转化器
2019-09-19 18:10:04 】 浏览:49
Tags:wpf datagrid field image converter 字段 图片 转化
 
 
1 <DataGridTemplateColumn Header="Binding">
2                             <DataGridTemplateColumn.CellTemplate>
3                                 <DataTemplate>
4                                     <Image x:Name="BindImg" Height="30" Width="30" Source="{Binding IsBindable,Converter={StaticResource bindableConverter}}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
5                                 </DataTemplate>
6                             </DataGridTemplateColumn.CellTemplate>                             
7                         </DataGridTemplateColumn>
 1 public class BindableConverter : IValueConverter
 2     {
 3         public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
 4         {
 5             bool isBind;
 6             if(value==null||string.IsNullOrWhiteSpace(value.ToString()))
 7             {
 8                 return "../../Resource/Images/unbinded.jpg";
 9             }
10             if (Boolean.TryParse(value.ToString(), out isBind))
11             {
12                 if (isBind)
13                 {
14                     return "../../Resource/Images/binded.jpg";
15                 }
16                 else
17                 {
18                     return "../../Resource/Images/unbinded.jpg";
19                 }
20             }
21             return null;
22         }
23 
24         public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
25         {
26             throw new NotImplementedException();
27         }
28     }

 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇C#中一行代码实现18位数字时间戳.. 下一篇C#上手练习6(方法语句1)

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目