Color Picker
A drop-down colour picker in the style of Microsoft Office: a box showing the chosen colour, and a palette of theme colours, their tints and shades, and standard colours, with a "More Colors" window for any named colour or an exact A/R/G/B value.
Assembly
| Assembly | Binarymission.WPF.Controls.ExtendedColorPicker.dll |
| Root namespace | Binarymission.WPF.Controls.Pickers |
| Target frameworks | .NET Framework 4.8, .NET 6 / 8 / 10 |
| Depends on | Skinning |
Overview
Use it wherever the user chooses a colour – text and highlight colours in an editor, the
series colours of a chart, a category colour in a calendar, a theme setting. The chosen colour is
SelectedColorBrush, and SelectedColorChanged tells you when the user
chooses another.
What the user sees
- The face: a swatch of the selected colour, the colour's values as text
(
SelectedColorName) and a drop-down button. - The palette, opened by the button: a row of ten theme colours with five rows of their tints and shades, a row of ten standard colours, and a "More Colors" row. One click on a swatch chooses it and closes the palette.
- The "More Colors" window, opened by the "..." button on that row: every named WPF colour as a swatch, and boxes to type an exact alpha, red, green and blue value (0 to 255), set with the "Set" button or Enter. A colour chosen here is also kept on the palette's "More Colors" row, to be chosen again with one click.
Appearance
Every part has its own colours: the face (Control.Background,
Control.BorderBrush, SelectedColorTextForeground), the drop-down button
(DropDownButtonBackground, DropDownArrowFill), the palette
(PopupWindowBackground, ColorBoxMouseOverBorderBrush) and the "More
Colors" window (CustomColorsPopupInternalViewBackground and the other
CustomColorsPopup* properties). The defaults given on each property are the ones the
default style sets with no Binarymission skin in force; with a skin in force they follow the skin,
and a brush set on the control wins over both. Every caption – ThemeColorsLabelText,
MoreColorsLabelText and the rest – can be replaced, for example to translate the
control.
The default style makes the control 172 by 24 logical pixels; set
FrameworkElement.Width and FrameworkElement.Height to change it.
Getting started
A text-colour picker in a formatting toolbar, applying the chosen colour to the selected text.
<Window x:Class="Editor.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:pickers="clr-namespace:Binarymission.WPF.Controls.Pickers;assembly=Binarymission.WPF.Controls.ExtendedColorPicker"
Title="Editor" Width="800" Height="500">
<DockPanel>
<ToolBar DockPanel.Dock="Top">
<TextBlock Text="Font colour:" VerticalAlignment="Center" Margin="4,0" />
<pickers:ExtendedOfficeColorPicker x:Name="FontColour"
SelectedColorBrush="#1A3E72"
ShouldDisplayAlphaValue="False"
IsControlWindowCurvedEdged="True"
SelectedColorChanged="OnFontColourChanged" />
</ToolBar>
<RichTextBox x:Name="Document" />
</DockPanel>
</Window>The handler.
using System.Windows;
using System.Windows.Documents;
private void OnFontColourChanged(object sender, RoutedEventArgs e)
{
Document.Selection.ApplyPropertyValue(TextElement.ForegroundProperty, FontColour.SelectedColorBrush);
Document.Focus();
}API reference
Binarymission.WPF.Controls.Pickers
class ExtendedOfficeColorPicker | A drop-down colour picker in the style of Microsoft Office: a box showing the chosen colour, and a palette of theme colours, their tints and shades, and standard colours, with a "More Colors" window for any named colour or an exact A/R/G/B value. |