文章链接:http://www.codeproject.com/KB/WPF/FormatColorDialog.aspx
Introduction
由于WPF现在还未实现颜色选择对话框,但是很多的软件中需要用到颜色对话框,次对话框是在毕设中的一个实现模块,其能够实现纯色,线性渐变画刷,径向渐变画刷的配置。
Background
Using the code
类ColorDialog是个类似windows颜色对话框的WPF颜色对话框。
FormatColorDialog dlg = new FormatColorDialog(this.b.BorderBrush, this.b.Background, this.rect.Fill);
dlg.Owner = this;
if (true == dlg.ShowDialog())
{
this.border.BorderBrush = dlg.LineBrush;
this.border.Background = dlg.FillBrush;
this.rectangle.Fill = dlg.BackgroundBrush;
}
类FormatColorDialog是应用了三个ColorChooser画刷选择列表,用来分别配置线画刷,填充画刷和背景画刷。
类ColorChooser是封装了一个BrushConfigurer的颜色选择下拉列表控件。
xmlns:c="clr-namespace:NWPU.CS.ConfigurationSoftware.DialogControls"
<c:ColorChooser x:Name="cbLine"></c:ColorChooser>
类BrushConfigurer是封装了SolidBrushConfigurer,LinearGradientBrushConfigurer,RadioGradientBrushConfigurer的实例的画刷配置控件。
类SolidBrushConfigurer,LinearGradientBrushConfigurer,RadioGradientBrushConfigurer分别为纯色,线性渐变,径向渐变画刷的配置控件。