Declaration
This article demonstrates how you can declare a RadColorSelector and populate it with colors.
Selection
-
RadColorSelector has a SelectedColor property, which is of type Color and it is used to store selected color value.
<telerik:RadColorSelector SelectedColor="Red" />
RadColorSelector colorSelector = new RadColorSelector(); colorSelector.SelectedColor = Colors.Red;
Dim colorSelector As New RadColorSelector() colorSelector.SelectedColor = Colors.Red
-
Whenever a color is selected the SelectedColorChanged event is raised:
colorSelector.SelectedColorChanged += new EventHandler(colorSelector_SelectedColorChanged); void colorSelector_SelectedColorChanged(object sender, EventArgs e) { RadColorSelector selector = sender as RadColorSelector; Color selectedColor = selector.SelectedColor; }
colorSelector.SelectedColorChanged += New EventHandler(colorSelector_SelectedColorChanged) Private Sub colorSelector_SelectedColorChanged(ByVal sender As Object, ByVal e As EventArgs) Dim selector As RadColorSelector = TryCast(sender, RadColorSelector) Dim selectedColor As Color = selector.SelectedColor End Sub
Populating
You can populate the RadColorSelector with any of the built-in palettes using the ColorPreset enumeration. It has HeaderPalette, MainPalette and StandardPalette properties, which represent the corresponding parts of the selector.
-
MainPalette property:
<telerik:RadColorSelector MainPalette="Grayscale" />
RadColorSelector colorSelector = new RadColorSelector(); colorSelector.MainPalette = ColorPreset.Grayscale;
Dim colorSelector As New RadColorSelector() colorSelector.MainPalette = ColorPreset.Grayscale
-
HeaderPalette property:
<telerik:RadColorSelector HeaderPalette="Office" />
RadColorSelector colorSelector = new RadColorSelector(); colorSelector.HeaderPalette = ColorPreset.Office;
Dim colorSelector As New RadColorSelector() colorSelector.HeaderPalette = ColorPreset.Office
-
StandardPalette property:
<telerik:RadColorSelector StandardPalette="Standard" />
RadColorSelector colorSelector = new RadColorSelector(); colorSelector.StandardPalette = ColorPreset.Standard;
Dim colorSelector As New RadColorSelector() colorSelector.StandardPalette = ColorPreset.Standard
-
If you prefer to use your own collection of Colors you can always use HeaderPaletteItemsSource, MainPaletteItemsSource and StandardPaletteItemsSource.
-
StandardPaletteItemSource property
<telerik:RadColorSelector StandardPaletteItemsSource="{Binding Source={StaticResource ColorList}}" />
RadColorSelector colorSelector = new RadColorSelector(); colorSelector.StandardPaletteVisibility = Visibility.Visible; Collection<Color> colors = new Collection<Color>(); colors.Add(Colors.Red); colors.Add(Colors.Green); colors.Add(Colors.Blue); colorSelector.StandardPaletteItemsSource = colors;
Dim colorSelector As New RadColorSelector() colorSelector.StandardPaletteVisibility = Visibility.Visible Dim colors As New Collection(Of Color)() _colors.Add(Colors.Red) _colors.Add(Colors.Green) _colors.Add(Colors.Blue) _colorSelector.StandardPaletteItemsSource = _colors
-
HeaderPaletteItemSource property
<telerik:RadColorSelector HeaderPaletteItemsSource="{Binding Source={StaticResource ColorList}}" />
RadColorSelector colorSelector = new RadColorSelector(); colorSelector.HeaderPaletteVisibility = Visibility.Visible; Collection<Color> colors = new Collection<Color>(); colors.Add(Colors.Red); colors.Add(Colors.Green); colors.Add(Colors.Blue); colorSelector.HeaderPaletteItemsSource = colors;
Dim colorSelector As New RadColorSelector() colorSelector.HeaderPaletteVisibility = Visibility.Visible Dim _colors As New Collection(Of Color)() _colors.Add(Colors.Red) _colors.Add(Colors.Green) _colors.Add(Colors.Blue) colorSelector.HeaderPaletteItemsSource = _colors
-
MainPaletteItemSource property
<telerik:RadColorSelector MainPaletteItemsSource="{Binding Source={StaticResource ColorList}}" />
RadColorSelector colorSelector = new RadColorSelector(); Collection<Color> colors = new Collection<Color>(); colors.Add(Colors.Red); colors.Add(Colors.Green); colors.Add(Colors.Blue); colorSelector.MainPaletteItemsSource = colors;
Dim colorSelector As New RadColorSelector() Dim _colors As New Collection(Of Color)() _colors.Add(Colors.Red) _colors.Add(Colors.Green) _colors.Add(Colors.Blue) colorSelector.MainPaletteItemsSource = _colors
-