C# 如何在metro应用程序中向组合框添加颜色?
我想在metro应用程序中使用C#向组合框添加颜色列表。反过来,用户可以从列表中选择特定颜色来更改背景 可能可用的库是Windows.UI.Colors 以下是一个简单桌面应用程序的链接: 但我无法将其移植到metro环境 此外,颜色名称以及颜色本身作为一个列表项将是一个巨大的优势 MSDN中的另一个线程:C# 如何在metro应用程序中向组合框添加颜色?,c#,windows-8,microsoft-metro,C#,Windows 8,Microsoft Metro,我想在metro应用程序中使用C#向组合框添加颜色列表。反过来,用户可以从列表中选择特定颜色来更改背景 可能可用的库是Windows.UI.Colors 以下是一个简单桌面应用程序的链接: 但我无法将其移植到metro环境 此外,颜色名称以及颜色本身作为一个列表项将是一个巨大的优势 MSDN中的另一个线程: 这是xaml文件 private static void LoadColors() { var t = typeof(Colors); var ti = t.GetTy
这是xaml文件
private static void LoadColors()
{
var t = typeof(Colors);
var ti = t.GetTypeInfo();
var dp = ti.DeclaredProperties;
colors = new List<PropertyInfo>();
foreach (var item in dp)
{
colors.Add(item);
}
}
private static List<PropertyInfo> colors;
public List<PropertyInfo> Colors
{
get
{
if (colors == null)
LoadColors();
return colors;
}
}
private static void LoadColors()
{
var t=类型(颜色);
var ti=t.GetTypeInfo();
var dp=ti.申报财产;
颜色=新列表();
foreach(dp中的var项目)
{
颜色。添加(项目);
}
}
私有静态列表颜色;
公共列表颜色
{
得到
{
如果(颜色==null)
LoadColors();
返回颜色;
}
}
这是C代码
感谢大家的支持和帮助。此代码适用于我:
var colorsTypeInfo = typeof(Colors).GetTypeInfo();
var properties = colorsTypeInfo.DeclaredProperties;
Dictionary<string, string> colours = new Dictionary<string, string>();
foreach (var dp in properties)
{
colours.Add(dp.Name, dp.GetValue(typeof(Colors)).ToString());
}
你把代码移植到metro有多远?罗兰肖:一点也不。正如我所提到的,图书馆之间的差异太大了,无法做太多的事情。此外,GetProperties()也不可用。另外,XAML中也有,但我不知道它的用法。
var colorsTypeInfo = typeof(Colors).GetTypeInfo();
var properties = colorsTypeInfo.DeclaredProperties;
Dictionary<string, string> colours = new Dictionary<string, string>();
foreach (var dp in properties)
{
colours.Add(dp.Name, dp.GetValue(typeof(Colors)).ToString());
}
using System.Reflection;
using Windows.UI;