Creating a Custom Palette

ColorPicker for 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:

1.   Click once within the UserControl to select it.

2.   Navigate to the ToolBox and double-click the Button control to add it to the project.

3.   Resize and reposition the Button on the page.

4.   Change the Button's default content by replacing the Content markup with Content="Change Palette" in the button's XAML tag.

5.   Give the control a name and add an event handler, by adding Name="btn1" Click="btn1_Click" to the button's XAML tag.

6.   Switch to Code view and add code for the Button_Click event handler:

      Visual Basic

      C#

The ColorPicker's color palette will now change to a custom palette when the button is clicked.

Run the application and observe:

Observe the following:

1.   Click the C1ColorPicker control's drop-down arrow, and notice that the default palette appears.

2.   Click the Change Palette button and click the C1ColorPicker control's drop-down arrow once again. Notice that the custom palette appears:

 


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.