今天分享一个 WPF 版的ColorDialog,该控件源自 这里,不过笔者已经该控件做了大量的修改工作,以适应自己的产品需求,闲话少说,先看看效果图:
1、DropDownCustomColorPicker 效果图
先看原项目的(喜欢这种方式的,请到 这里 下载源码 )
被笔者修改之后的效果图:
二、DropDownCustomColorPicker 四种颜色选择方式
第一种:单击任意一个预定义的颜色即可。
这些颜色通过反射 Colors 中的属性获得的, 笔者 对这些颜色进行排序,视觉效果更美观了。
/// <summary> /// 反射预定义颜色 /// </summary> public class CustomColors { List<Color> selectableColors = null; public List<Color> SelectableColors { get { return selectableColors; } set { selectableColors = value; } } public CustomColors() { var list = new List<Color>(); Type ColorsType = typeof(Colors); PropertyInfo[] ColorsProperty = ColorsType.GetProperties(); foreach (PropertyInfo property in ColorsProperty) { list.Add((Color)ColorConverter.ConvertFromString(property.Name)); } list.Sort(new Comparison<Color>((Color x, Color y) => { var xtotal = x.R + x.G + x.B; var ytotal = y.R + y.G + y.B; return xtotal.CompareTo(ytotal); // 升序排列 })); selectableColors = list; } }