博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

wpf转换器

方面进行转换绑定

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Windows.Data;
 6 
 7 namespace NetReform
 8 {
 9     [ValueConversion(typeof(string), typeof(string))]
10     class ReadBtnBKConvert : IValueConverter
11     {
12         public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
13         {
14             string b = "000";
15 
16             string reValue = System.Convert.ToString(value);
17             if (reValue == "green")
18             {
19                 b = "0";
20             }
21             else if (reValue == "yellow")
22             {
23                 b = "1";
24             }           
25             else if (reValue == "")
26             {
27                 b = "";
28             }
29             else
30             {
31                 b = "1";//其它为1
32             }
33             return b;
34         }
35 
36         public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
37         {
38             throw new NotImplementedException();
39         }
40     }
41 }

 

posted @ 2016-04-07 19:26  ants_double  阅读(165)  评论(0编辑  收藏  举报