在 .NET 中有一个类可以将文本 HTML 颜色名称转换为颜色(在本例中为“红色”):
Color col=(Color)ColorConverter.ConvertFromString("Red");
Brush brush=new SolidColorBrush(col);
(我从这里拿的:Cast Color Name to SolidColorBrush)
这几乎适用于 all the colours that can be found on wikipedia
Windows Store Apps 是否有可以做同样事情的等效类/库?
请您参考如下方法:
试试这个
using System.Reflection;
public SolidColorBrush ColorStringToBrush(string name)
{
var property = typeof(Colors).GetRuntimeProperty(name);
if (property != null)
{
return new SolidColorBrush((Color)property.GetValue(null));
}
else
{
return null;
}
}
