Colors包含很多静态属性颜色,应该是以前Form里面的KnownColor。现在做一个取色框大概就是下面这样。
通过反射方式获取Colors的所有静态属性。
public ObservableCollection<UserColor> CreateColorCollection() {
var colorCollection = new ObservableCollection<UserColor>();
var colorProperties = typeof(Colors).GetProperties();
foreach (PropertyInfo p in colorProperties)
{
if (p.PropertyType== typeof(Color))
{
var c = new UserColor();
c.Name = p.Name;
c.Value = (Color)p.GetValue(null);
c.Brush = new SolidColorBrush(c.Value);
colorCollection.Add(c);
//Debug.WriteLine($"ColorName:{p.Name}Color2String{color.ToString()}");
}
}
return colorCollection;
}
public class UserColor {
public string Name { get; set; }
public Color Value { get; set; }
public SolidColorBrush Brush { get; set; }
}
end