ColorPicker > C1ColorPicker Task-Based Help > Creating a Custom Palette |
ColorPicker for WPF and Silverlight includes over 20 predefined color palettes that match the themes used in Microsoft Office, but if you choose you can create your own custom color palette rather than using a predefined one. In the following steps you'll create a custom palette, and when a button is pressed, apply that palette to the C1ColorPicker control.
To create a custom palette, complete the following steps:
Visual Basic Copy Code Private Sub Button1_Click(ByVal sender as Object, ByVal e as System.Windows.RoutedEventArgs) ' Set the color palette. Dim cp1 as New ColorPalette("Pittsburgh") cp1.Clear() cp1.Add(Color.FromArgb(255, 0, 0, 0)) cp1.Add(Color.FromArgb(255, 99, 107, 112)) cp1.Add(Color.FromArgb(255, 255, 255, 255)) cp1.Add(Color.FromArgb(255, 247, 181, 18)) cp1.Add(Color.FromArgb(255, 253, 200, 47)) cp1.Add(Color.FromArgb(255, 43, 41, 38)) cp1.Add(Color.FromArgb(255, 149, 123, 77)) cp1.Add(Color.FromArgb(255, 209, 201, 157)) cp1.Add(Color.FromArgb(255, 0, 33, 71)) cp1.Add(Color.FromArgb(255, 99, 177, 229)) c1ColorPicker1.Palette = cp1 End Sub
C# Copy Code private void button1_Click(object sender, System.Windows.RoutedEventArgs e) { // Set the color palette. ColorPalette cp1 = new ColorPalette("Pittsburgh"); cp1.Clear(); cp1.Add(Color.FromArgb(255, 0, 0, 0)); cp1.Add(Color.FromArgb(255, 99, 107, 112)); cp1.Add(Color.FromArgb(255, 255, 255, 255)); cp1.Add(Color.FromArgb(255, 247, 181, 18)); cp1.Add(Color.FromArgb(255, 253, 200, 47)); cp1.Add(Color.FromArgb(255, 43, 41, 38)); cp1.Add(Color.FromArgb(255, 149, 123, 77)); cp1.Add(Color.FromArgb(255, 209, 201, 157)); cp1.Add(Color.FromArgb(255, 0, 33, 71)); cp1.Add(Color.FromArgb(255, 99, 177, 229)); c1ColorPicker1.Palette = cp1; }
The ColorPicker's color palette will now change to a custom palette when the button is clicked.