
There are diverse color pickers on the net (see e.g. the framework sample, a more elaborate sample on CodeProject, Telerik’s commercial version…) but none of them were really what we were looking for, so we set aside a few hours to cook something. The color picker we were looking for had to be flexible and templated, support both solid colors and gradients. The screenshot next shows some of the templates we assembled.
This custom WPF control is a standard example of databinding, control templating, routed events, dependency properties and XAML fun. Looking at the code of commercial controls we wonder why they make things so complicated sometimes…
Thank you, çois !
By Sven August 10, 2009 - 9:17 amThak you.
By jlrvpuma September 1, 2009 - 9:10 amThank you.
By jlrvpuma September 2, 2009 - 7:14 amBut How do you do if you want to save color´s values in an xml.
This xml could be a config file.
save normal Color´s values in an xml is easy, but saving gradients or semitransparents colors is , is…I don know how to do.
Fairly easy. Use XamlWriter.Save(SomeBrush) to save to a XAML string and XamlReader.Parse(XamlString) to read an XML string (representing a gradient brush).
By Francois September 2, 2009 - 7:22 amThanks dude, very handy. Have you thought of ways to package both the templates and classes together so that in the future you can simply add a reference to your color picker library and and use it without manually adding the resources?
By Leigh November 14, 2009 - 2:43 amthe link is broken
By MWS July 29, 2010 - 3:04 amFixed, thanks a bunch for letting know!
By Francois July 29, 2010 - 5:26 amHi,
thanks a lot. I’m very satisfied with this color picker. But there might be a bug (or I might be wrong).
I have MyObject, that implement INotifyPropertyChanged with Brush property. Than I have a list of MyObjects displayed in ListBox. On a SelectionChanged I can see the detail of selected MyObject in another StackPanel. In this StackPanel is placed ColorPicker with binded property CurrentColor to my brush property on MyObject.
When I’m selecting the objects in collection – everything is just fine. After I change the color with picker on one, the displayed color in ColorApplyButton will not changed when selecting other MyObjects in collection. If I pickup another color from picker, the color is changed on correct MyObject, and the color of ColorApplyButton changes, but than is not changed when selecting.
I hope It makes sence to you an you can see where I’m getting.
Thanks …
By Kovi January 20, 2011 - 2:45 pmThank you
By Anas Al-Homsi August 6, 2011 - 10:29 am