这里给出一个通用的解决方案,虽然复杂了一些,但是可用性和扩张性均有大大提高。
显然这里自己去实现自定义格式化,即通过IFormatable、IFormatProvider、ICustomFormatter等接口已达到Globalization有点小题大作了,而另外一个很容易想到的点是通过DiaplayMember实现显示值得自定义(对于简单Binding,例如ComboBox、ListBox等只用重载ToString就可以了)。
既然有了方向,那就动手了。
首先,我们希望Binding整个枚举类型的每一个值,也就是说,我们需要把这个枚举的所有值变成一个数据源,为了实现这一点,我们可以使用Enum上的helper方法 Enum.GetValues(Type)来返回一个对所有值得枚举,然后依次添加到IList对象或者IListSource接口即可。
1
if
(
!
typeof
(EnumType).IsEnum)
2![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
throw new NotSupportedException("Can not support type: " + typeof(EnumType).FullName);
4
// It's better use resource version as below.
5
// throw new NotSupportedException(SR.GetString("TYPE_NOT_SUPPORT", typeof(EnumType).FullName));
6
}
7![](/Images/OutliningIndicators/None.gif)
8
//
Use Enum helper enumerator list all enum values and add to current context.
9
foreach
(EnumType value
in
Enum.GetValues(
typeof
(EnumType)))
10![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
11
//TODO: add each value to IList
12
base.Add(new EnumAdapter(value));
13
}
然后,取到了值,由于我们希望自定义Binding显示,那么需要对枚举值进行封装,而在这个封装里面,我们可以实现多语言的支持。
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/None.gif)
10
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
1
/**/
/// <summary>
2
/// Enum value adapter, used to get values from each Cultures.
3
/// </summary>
4
public
sealed
class
EnumAdapter
5![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
6![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
7
/// Storage the actual Enum value.
8
/// </summary>
9
private EnumType _value;
10![](/Images/OutliningIndicators/InBlock.gif)
11![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
12
/// Constructor an <see cref="EnumAdapter"/>.
13
/// </summary>
14
/// <param name="value">The enum value.</param>
15
/// <exception cref="">
16
///
17
/// </exception>
18
public EnumAdapter(EnumType value)
19![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
20
if (!Enum.IsDefined(typeof(EnumType), value))
21![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
22
throw new ArgumentException(string.Format("{0} is not defined in {1}", value, typeof(EnumType).Name), "value");
23
// It's better use resource version as below.
24
// throw new ArgumentException(SR.GetString("ENUM_NOT_DEFINED_FMT_KEY", value, typeof(EnumType).Name), "value");
25
}
26
_value = value;
27
}
28![](/Images/OutliningIndicators/InBlock.gif)
29![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
30
/// Gets the actual enum value.
31
/// </summary>
32
public EnumType Value
33![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
34![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return _value; }
35
}
36![](/Images/OutliningIndicators/InBlock.gif)
37![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
/**//// <summary>
38
/// Gets the display value for enum value by search local resource with currrent UI culture
39
/// and special key which is concated from Enum type name and Enum value name.
40
/// </summary>
41
/// <remarks>
42
/// This would get correct display value by accessing location resource with current UI Culture.
43
/// </remarks>
44
public string DisplayValue
45![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
46![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
get
{ return SR.GetString(string.Format("{0}.{1}", typeof(EnumType).Name, _value.ToString())); }
47
}
48![](/Images/OutliningIndicators/InBlock.gif)
49
//TODO: If you want more, please add below![](https://www.cnblogs.com/Images/dot.gif)
50
}
至此,整个功能的框架已经完成,下面我们来看看一些细节——如何对资源读取和管理的封装:
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
2
![](/Images/OutliningIndicators/InBlock.gif)
3
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
6
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
12
![](/Images/OutliningIndicators/InBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/InBlock.gif)
16
![](/Images/OutliningIndicators/InBlock.gif)
17
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/InBlock.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
26
![](/Images/OutliningIndicators/InBlock.gif)
27
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
30
![](/Images/OutliningIndicators/InBlock.gif)
31
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
34
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
35
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
36
![](/Images/OutliningIndicators/InBlock.gif)
37
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/InBlock.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/InBlock.gif)
43
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
44
![](/Images/OutliningIndicators/InBlock.gif)
45
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
46
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
47
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
50
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
1
/**/
/// <summary>
2
/// Constructor a new <see cref="SR"/>.
3
/// </summary>
4
internal
SR()
5![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
6
//TODO: If you modified resource location, please update here![](https://www.cnblogs.com/Images/dot.gif)
7
this.resources = new System.Resources.ResourceManager(
8
string.Concat(typeof(EnumAdapter).Namespace, ".Resource"),
9
base.GetType().Assembly);
10
}
11![](/Images/OutliningIndicators/None.gif)
12![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**/
/// <summary>
13
/// Get singleton instance.
14
/// </summary>
15
/// <returns>A singleton <see cref="SR"/></returns>
16
private
static
SR GetLoader()
17![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
18
if (loader == null)
19![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
20
lock (SR.InternalSyncObject)
21![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
22
if (loader == null)
23![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
24
loader = new SR();
25
}
26
}
27
}
28
return loader;
29
}
30![](/Images/OutliningIndicators/None.gif)
31![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**/
/// <summary>
32
/// Gets an object from resources by special key, which provided by <paramref name="name"/>.
33
/// </summary>
34
/// <param name="name">Resource accessed key</param>
35
/// <returns>return stored object in resource. if resource not found, return <paramref name="name"/> as object.</returns>
36
public
static
object
GetObject(
string
name)
37![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
38
SR loader = GetLoader();
39
if (loader == null)
40![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
41
return null;
42
}
43
try
44![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
45
return loader.resources.GetObject(name, Culture);
46
}
47![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
catch
{ }
48
return name;
49
}
50![](/Images/OutliningIndicators/None.gif)
51![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**/
/// <summary>
52
/// Gets a string from resources by special key, which provided by <paramref name="name"/>.
53
/// </summary>
54
/// <param name="name">Resource accessed key</param>
55
/// <returns>return stored string in resource. If resource not found, retuen <paramref name="name"/> as result.</returns>
56
public
static
string
GetString(
string
name)
57![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
58
SR loader = GetLoader();
59
if (loader == null)
60![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
61
return null;
62
}
63
try
64![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
65
return loader.resources.GetString(name, Culture);
66
}
67![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
catch
{ }
68
return name;
69
}
70![](/Images/OutliningIndicators/None.gif)
71![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
/**/
/// <summary>
72
/// Gets a formatted string from resources by special key, which provided by <paramref name="name"/> and optional parameters.
73
/// </summary>
74
/// <param name="name">Resource accessed key</param>
75
/// <param name="args">format arguments.</param>
76
/// <returns>return stored string in resource. If resource not found, use <paramref name="name"/> as formator, return the formatted string.</retur
77
public static string GetString(string name, params object[] args)
78
{
79
SR loader = GetLoader();
80
if (loader == null)
81![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
82
return null;
83
}
84
string format = name;
85
try
86![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
87
format = loader.resources.GetString(name, Culture);
88
}
89![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
catch
{ }
90![](/Images/OutliningIndicators/InBlock.gif)
91
if ((args == null) || (args.Length <= 0))
92![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
93
return format;
94
}
95![](/Images/OutliningIndicators/InBlock.gif)
96
// It's better cut long arg for formating.
97
for (int i = 0; i < args.Length; i++)
98![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
99
string arg = args[i] as string;
100
if ((arg != null) && (arg.Length > 0x400))
101![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
102
args[i] = arg.Substring(0, 0x3fd) + "
";
103
}
104
}
105
return string.Format(System.Globalization.CultureInfo.CurrentCulture, format, args);
106
}
OK,大功告成,有了这么一个封装,在应用里就可以简单的这么几句够搞定。
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
2
![](/Images/OutliningIndicators/InBlock.gif)
3
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
4
![](/Images/OutliningIndicators/None.gif)
5
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
6
![](/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
7
![](/Images/OutliningIndicators/InBlock.gif)
8
![](/Images/OutliningIndicators/InBlock.gif)
9
![](/Images/OutliningIndicators/InBlock.gif)
10
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
11
![](/Images/OutliningIndicators/None.gif)
12
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
13
![](/Images/OutliningIndicators/InBlock.gif)
14
![](/Images/OutliningIndicators/InBlock.gif)
15
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
16
![](/Images/OutliningIndicators/None.gif)
17
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
18
![](/Images/OutliningIndicators/InBlock.gif)
19
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
20
![](/Images/OutliningIndicators/InBlock.gif)
21
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
22
![](/Images/OutliningIndicators/InBlock.gif)
23
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
24
![](/Images/OutliningIndicators/InBlock.gif)
25
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
26
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
27
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
28
![](/Images/OutliningIndicators/InBlock.gif)
29
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
30
![](/Images/OutliningIndicators/None.gif)
31
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
32
![](/Images/OutliningIndicators/InBlock.gif)
33
![](/Images/OutliningIndicators/InBlock.gif)
34
![](/Images/OutliningIndicators/InBlock.gif)
35
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
36
![](/Images/OutliningIndicators/None.gif)
37
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
38
![](/Images/OutliningIndicators/InBlock.gif)
39
![](/Images/OutliningIndicators/InBlock.gif)
40
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
41
![](/Images/OutliningIndicators/InBlock.gif)
42
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
43
![](/Images/OutliningIndicators/InBlock.gif)
44
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
45
![](/Images/OutliningIndicators/InBlock.gif)
46
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
47
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
48
![](/Images/OutliningIndicators/InBlock.gif)
49
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
50
![](/Images/OutliningIndicators/None.gif)
51
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
52
![](/Images/OutliningIndicators/InBlock.gif)
53
![](/Images/OutliningIndicators/InBlock.gif)
54
![](/Images/OutliningIndicators/InBlock.gif)
55
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
56
![](/Images/OutliningIndicators/None.gif)
57
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
58
![](/Images/OutliningIndicators/InBlock.gif)
59
![](/Images/OutliningIndicators/InBlock.gif)
60
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
61
![](/Images/OutliningIndicators/InBlock.gif)
62
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
63
![](/Images/OutliningIndicators/InBlock.gif)
64
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
65
![](/Images/OutliningIndicators/InBlock.gif)
66
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
67
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
68
![](/Images/OutliningIndicators/InBlock.gif)
69
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
70
![](/Images/OutliningIndicators/None.gif)
71
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
72
![](/Images/OutliningIndicators/InBlock.gif)
73
![](/Images/OutliningIndicators/InBlock.gif)
74
![](/Images/OutliningIndicators/InBlock.gif)
75
![](/Images/OutliningIndicators/InBlock.gif)
76
![](/Images/OutliningIndicators/InBlock.gif)
77
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
78
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
79
![](/Images/OutliningIndicators/InBlock.gif)
80
![](/Images/OutliningIndicators/InBlock.gif)
81
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
82
![](/Images/OutliningIndicators/InBlock.gif)
83
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
84
![](/Images/OutliningIndicators/InBlock.gif)
85
![](/Images/OutliningIndicators/InBlock.gif)
86
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
87
![](/Images/OutliningIndicators/InBlock.gif)
88
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
89
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
90
![](/Images/OutliningIndicators/InBlock.gif)
91
![](/Images/OutliningIndicators/InBlock.gif)
92
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
93
![](/Images/OutliningIndicators/InBlock.gif)
94
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
95
![](/Images/OutliningIndicators/InBlock.gif)
96
![](/Images/OutliningIndicators/InBlock.gif)
97
![](/Images/OutliningIndicators/InBlock.gif)
98
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
99
![](/Images/OutliningIndicators/InBlock.gif)
100
![](/Images/OutliningIndicators/InBlock.gif)
101
![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](/Images/OutliningIndicators/ContractedSubBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
102
![](/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
103
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
104
![](/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
105
![](/Images/OutliningIndicators/InBlock.gif)
106
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
1
private
void
Form1_Load(
object
sender, EventArgs e)
2![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
3
this.comboBox1.DataSource = new EnumDataSource<Sex>();
4
this.comboBox1.DisplayMember = "DisplayValue";
5
this.comboBox1.ValueMember = "Value";
6
}
7![](/Images/OutliningIndicators/None.gif)
8
public
enum
Sex
9![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
10
Male,
11
Female
12
}
你可以从这里下载本篇中的相关示例代码:
![](/Images/OutliningIndicators/None.gif)
2
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
3
![](/Images/OutliningIndicators/InBlock.gif)
4
![](/Images/OutliningIndicators/InBlock.gif)
5
![](/Images/OutliningIndicators/InBlock.gif)
6
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
7
![](/Images/OutliningIndicators/None.gif)
8
![](/Images/OutliningIndicators/None.gif)
9
![](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](/Images/OutliningIndicators/ContractedBlock.gif)
![](https://www.cnblogs.com/Images/dot.gif)
10
![](/Images/OutliningIndicators/InBlock.gif)
11
![](/Images/OutliningIndicators/InBlock.gif)
12
![](/Images/OutliningIndicators/ExpandedBlockEnd.gif)
http://www.cnblogs.com/Files/winkingzhang/Demo_2008_03_25.rar