A WPF Color Picker

A templated color picker for WPF. Pretty much the prototypical example of a custom WPF control with databinding, templating, routed events, dependency properties and so on.

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 I was looking for, so I set aside a few hours to cook something myself. The color picker I was looking for had to be flexible and templated, support both solid colors and gradients. The screenshot below shows some of the templates I assembled:

ColorPicker Sample

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 I wonder why they make things so complicated sometimes…

Download Color Picker 1.6 (Tue 27 Apr 2010)

 

7 Responses to “A WPF Color Picker”

  1. Sven says:

    Thank you, çois !

  2. jlrvpuma says:

    Thank you.
    But 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.

  3. Francois says:

    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).

  4. Leigh says:

    Thanks 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?

  5. MWS says:

    the link is broken

  6. Francois says:

    Fixed, thanks a bunch for letting know!

Leave a Reply