【发布时间】:2014-07-01 07:39:22
【问题描述】:
我正在尝试获取所有颜色并用 mvvm 中的颜色列表填充我的列表框。为此我正在使用下面的代码,但它在下面的代码中给出了错误。请让我知道我错在哪里。
属性
private List<Color> _colorlist;
public List<Color> ColorList
{
get { return _colorlist; }
set
{
_colorlist = value;
RaisePropertyChanged(() => _colorlist);
}
}
List<Color> list = new List<Color>();
Type colorType = typeof(System.Drawing.Color);
if (null != colorType)
{
PropertyInfo[] propInfoList =
colorType.GetProperties(BindingFlags.Static | BindingFlags.DeclaredOnly
| BindingFlags.Public);
int nNumProps = propInfoList.Length;
for (int i = 0; i < nNumProps; i++)
{
PropertyInfo propInfo = (PropertyInfo)propInfoList[i];
object[] index = null;
list.Add((Color)propInfo.GetValue(null, index)); //Specified cast is not valid.
string strColorName = propInfo.Name;
}
}
【问题讨论】:
-
-1 用于提出质量很差的问题。尝试用文字来描述你的问题,不要只是把你的代码扔给我们...它在下面的代码中给出错误是不是有用的描述。