June 06
OpacitySlider Control
OpacitySlider control is designed as the Opacity value selector. It's the extension of the Slider control.
Read-write SelectedOpacity Dependency Property of the OpacitySlider control allows to get or set the value of Opacity. It's of the double type and its value is in the [0,1] range (0 means transparent, 1 - opaque, the default).
OpacitySlider SelectedOpacity property value is synchronized with Minimum, Maximum and Value properties values of the parent Slider control. To get or set the Opacity value the caller can use both OpacitySlider and Value properties taking into account the simple relation:
SelectedOpacity = 1.0 - (Value - Minimum) / (Maximum - Minimum);
OpacitySlider control overrides the default template of the parent Slider control and looks like follows:
i.e. its style redefines the slider background and the constituent Thumb control template.
As you can see at the figure above the OpacitySlider control takes into account the parent Slider control Orientation property and can be presented as the horizontal or the vertical bar.
The direction the Opacity value changes depends on the value of IsDirectionReversed property. If it's false (the default) the maximum opacity as at the left or at the bottom of the control depending on the orientation.
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 OpacitySliderSample project there.OpacitySlider control code is in the WPFGears library project ColorPickerControls folder.
Regards,
Oleg V. Polikarpotchkin