Category / Section
How can I add custom colors in the ColorPickerPallette control?
1 min read
In the ColorPickerPallette control, you can add custom colors to the palette by setting the CustomColorsCollection property. By using this property, you can bind the collections of custom colors and also enable the custom colors by setting the SetCustomColor property to true.
The following code shows how to use the CustomColorsCollection property.
XAML
<Window x:Class="ColorPickerPallette.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:syncfusion ="http://schemas.syncfusion.com/wpf" Title="MainWindow" Height="350" Width="525"> <Grid> <syncfusion:ColorPickerPalette x:Name="Color1" Width="200" Height="100" " CustomColorsCollection="{Binding PaletteColours}" SetCustomColors="True"/> </Grid> </Window>
C#
namespace ColorPickerPallette { /// <summary> /// Interaction logic for the MainWindow.xaml. /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); Color1.CustomColorsCollection = new ObservableCollection<CustomColor>() { new CustomColor() { Color = new Color() {R = 112, G = 48, B = 160, A = 255}, ColorName = "Purple" }, new CustomColor() { Color = new Color() {R = 0, G = 32, B = 96, A = 255}, ColorName = "Blue" }, new CustomColor() { Color = new Color() {R = 255, G = 0, B = 0, A = 255}, ColorName = "Red" }, new CustomColor() { Color = new Color() {R = 255, G = 192, B = 0, A = 255}, ColorName = "Yellow" }, new CustomColor() { Color = new Color() {R = 0, G = 176, B = 80, A = 255}, ColorName = "Green" }, }; } } }
The following screenshot shows how to use the CustomColors in the ColorPickerPallette control.