프로젝트

일반

사용자정보

개정판 6deaed53

ID6deaed5315affbbf73f4205c311f712f9333ccdc
상위 fb80055c
하위 469b2bbf

KangIngu 이(가) 6년 이상 전에 추가함

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

클립보드 이미지 추가 (최대 크기: 500 MB)