June 09
RainbowBox Element
This element is the one more control from the ColorPicker constituent controls bug in addition to the published in my recent posts.
RainbowBox element is designed as the tool to select a Color from the color spectrum and is close to the one in the Windows Common Color dialog. It extends the FrameworkElement.
The horizontal color spectrum is overlaid by the vertical gradient ranging from transparent color to Gray color. That is the sample.
You select the color with the color selector (small white circle with black border). You can drag it with the mouse or just click anywhere on the RainbowBox element surface. You can provide you own color selector drawing with the RainbowBox.Selector Dependency Property.
Read-only SelectedColor Dependency Property of the RainbowBox used to get the value of the Color selected. User can change the SelectedColor property from its code using the SelectorPosition property. The SelectorPosition property gets or sets the selector position normalized to [0,1 0,1] rectangle. Another way to change the SelectedColor property from the code is the RainbowBox.TrySetSelectedColor method. It gets the color argument and tries to find that color in the Rainbow. On success it sets the selector position accordingly and returns true; otherwise it returns false. When the SelectedColor changes the RainbowBox raises the SelectedColorChanged event.
The Rainbow Dependency Property allows to get or set the color spectrum. It's of the GradientStopCollection type i.e. represents the sequence of colors along with the position of the color in the spectrum. By default the spectrum is the sequence of equally spaced Red, Orange, Yellow, Green, Blue, Indigo, Violet, Red colors. When the Rainbow property changes the RainbowBox tries to find the current SelectedColor value in the new Rainbow. On success it sets the selector position accordingly; otherwise it sets the selector position to the top-left corner and changes its SelectedColor to the value corresponding to that position.
The code
You can download the code and the samples here:
The archive contains my WPFGears library with samples, tests, etc. It’s the Visual Studio 2008 SP1 solution targeted to .NET Framework 3.5.
You’ll find RainbowBoxSample project there. RainbowBox element code is in the WPFGears library project ColorPickerControls folder.
Regards,
Oleg V. Polikarpotchkin