개정판 6deaed53
Converter추가
KCOM/Common/Converter/enumStringColorConverter.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.ComponentModel; |
|
4 |
using System.Globalization; |
|
5 |
using System.Linq; |
|
6 |
using System.Reflection; |
|
7 |
using System.Text; |
|
8 |
|
|
9 |
namespace KCOM.Common.Converter |
|
10 |
{ |
|
11 |
public class EnumStringColorConverter : System.Windows.Data.IValueConverter |
|
12 |
{ |
|
13 |
|
|
14 |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
|
15 |
{ |
|
16 |
if (value != null) |
|
17 |
{ |
|
18 |
switch (value) |
|
19 |
{ |
|
20 |
case (int)IKCOM.FAVORITE_FLAG.Personal: |
|
21 |
{ |
|
22 |
return new System.Windows.Media.SolidColorBrush(StringToColorConverter.Parse(EnumExtension.ToDescription(IKCOM.FAVORITE_FLAG.Personal))); |
|
23 |
} |
|
24 |
break; |
|
25 |
case (int)IKCOM.FAVORITE_FLAG.TeamShare: |
|
26 |
{ |
|
27 |
return new System.Windows.Media.SolidColorBrush(StringToColorConverter.Parse(EnumExtension.ToDescription(IKCOM.FAVORITE_FLAG.TeamShare))); |
|
28 |
} |
|
29 |
break; |
|
30 |
default: |
|
31 |
{ |
|
32 |
return null; |
|
33 |
} |
|
34 |
break; |
|
35 |
} |
|
36 |
|
|
37 |
return null; |
|
38 |
} |
|
39 |
|
|
40 |
return null; |
|
41 |
} |
|
42 |
|
|
43 |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
|
44 |
{ |
|
45 |
throw new NotImplementedException(); |
|
46 |
} |
|
47 |
} |
|
48 |
|
|
49 |
public static class EnumExtension |
|
50 |
{ |
|
51 |
public static string ToDescription(this System.Enum value) |
|
52 |
{ |
|
53 |
FieldInfo fi = value.GetType().GetField(value.ToString()); |
|
54 |
var attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); |
|
55 |
return attributes.Length > 0 ? attributes[0].Description : value.ToString(); |
|
56 |
} |
|
57 |
} |
|
58 |
} |
KCOM/Common/Converter/enumStringConverter.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Globalization; |
|
4 |
using System.Linq; |
|
5 |
using System.Text; |
|
6 |
using System.Windows.Data; |
|
7 |
|
|
8 |
namespace KCOM.Common.Converter |
|
9 |
{ |
|
10 |
public class enumStringConverter : IValueConverter |
|
11 |
{ |
|
12 |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
|
13 |
{ |
|
14 |
if (value != null) |
|
15 |
{ |
|
16 |
switch (value) |
|
17 |
{ |
|
18 |
case (int)IKCOM.FAVORITE_FLAG.ALL: |
|
19 |
{ |
|
20 |
return "ALL"; |
|
21 |
} |
|
22 |
break; |
|
23 |
case (int)IKCOM.FAVORITE_FLAG.Personal: |
|
24 |
{ |
|
25 |
return "Personal"; |
|
26 |
} |
|
27 |
break; |
|
28 |
case (int)IKCOM.FAVORITE_FLAG.TeamShare: |
|
29 |
{ |
|
30 |
return "TeamShare"; |
|
31 |
} |
|
32 |
break; |
|
33 |
default: |
|
34 |
break; |
|
35 |
} |
|
36 |
//IKCOM.FAVORITE_FLAG |
|
37 |
|
|
38 |
} |
|
39 |
|
|
40 |
return null; |
|
41 |
} |
|
42 |
|
|
43 |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
|
44 |
{ |
|
45 |
throw new NotImplementedException(); |
|
46 |
} |
|
47 |
} |
|
48 |
} |
내보내기 Unified diff