wpf datagrid field to image converter 字段 图片转化器
程序员文章站
2022-07-01 23:25:52
1 2 3 4
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 }