关于组合框源代码的说明 [英] Explanation about source code of combobox
本文介绍了关于组合框源代码的说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发现这个源代码允许我直接将ComboBox绑定到枚举值,但我不明白这个指令
public IList< UserType> UserTypes
{
get
{
// 将导致列表如{Tester,Engineer}
return 枚举。 GetValues( typeof (UserType))。Cast< UserType>()。ToList< UserType>();
}
}
public UserType UserType
{
获得跨度>;
set ;
}
知道这个代码我在 site
我尝试过的事情:
i尝试测试这段代码但是它有效但不明白。
解决方案
查看此CodeProject文章在WPF中绑定和使用友好的枚举 [ ^ ]
但如果您对所找到的代码有疑问,那么您应该将问题转到作者 [< a href =http://www.ridgesolutions.ie/index.php/2014/11该代码的/ 05 / wpf-xaml-binding-combobox-direct-to-enum-values /target =_ blanktitle =New Window> ^ ]
< blockquote>
枚举
.GetValues(typeof(UserType))//获取枚举的所有值...这将返回一个对象数组
.Cast< UserType>() //将每个对象强制转换为枚举UserType - 这将返回IEnumerable< UserType>
.ToList< UserType>(); //转换IEnumerable< UserType>用户类型列表
这是非常基本的......就像问如何循环
I find this source code that allows me Binding ComboBox directly to enum values but I do not understand this instruction
public IList<UserType> UserTypes
{
get
{
// Will result in a list like {"Tester", "Engineer"}
return Enum.GetValues(typeof(UserType)).Cast<UserType>().ToList<UserType>();
}
}
public UserType UserType
{
get;
set;
}
knowing that this code I find it in this site
What I have tried:
i try to test this code and it's works but don't understand that.
解决方案
Have a look at this CodeProject article Binding and Using Friendly Enums in WPF[^]
But if you have a query about the code you found then you should direct your questions to the authors[^] of that code
Enum .GetValues(typeof(UserType)) // Get all values of the enum... This will return an array of object .Cast<UserType>() // cast each object to enum UserType - This will return a IEnumerable<UserType> .ToList<UserType>(); // Convert the IEnumerable<UserType> to a list of UserTypes
This is pretty basic... It is like asking how to loop
这篇关于关于组合框源代码的说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文