WPF Color Picker

WPF Color Picker
First Adding Reference to WPF Toolkit Extended Assembly

Creating a ColorPicker
wpf color picker

<Window x:Class="ExtendedWPF.ColorPicker"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:wpfx="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
        Title="ColorPicker" Height="300" Width="300">
    <Grid>
        <wpfx:ColorPicker Name="ColorPicker1" Height="30" Width="100" DisplayColorAndName="True" Margin="12,12,166,218" />
    </Grid>
</Window>

Output

color picker

Properties

The following is a list of some ColorPicker properties.

The AvailableColors property represents all colors that are available to the user for selection.

The AvailableColorsHeader property represents the header text of the Available Colors section.

The IsOpen property represents if dropdown is open.

The SelectedColor represents the currently selected color.

The SelectedColorText returns the known color name, or the color hexadecimal string of the SelectedColor.

The ShowAdvancedButton property represents if the Advanced is visible.

The ShowStandardColors property represents if the StandardColors is visible.

Listing 2 sets some of these properties at run-time.
private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ColorPicker1.IsOpen = true;
            ColorPicker1.SelectedColor = Colors.Green;
            ColorPicker1.ShowAdvancedButton = true;
        }

private void ColorPicker1_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color> e)
        {
            textBlock1.Foreground = new SolidColorBrush(ColorPicker1.SelectedColor);
        }

Output
Color picker with Properties
Color picker with Properties
WPF Color Picker WPF Color Picker Reviewed by Bhaumik Patel on 10:42 PM Rating: 5