Infragistics(R) NetAdvantage(R) : WPF 2012.1
Selected Color
E-mail your feedback on this topic.
Shared XAML > Editors > xamColorPicker > Using xamColorPicker > Selected Color

Glossary Item Box

The main property of the xamColorPicker control is the SelectedColor property. This property can be set in the following ways:

  1. You can set the property directly.

    In XAML:

    <ig:XamColorPicker x:Name="MyColorPicker" Width="100" 
                       Height="20" SelectedColor="Blue" >

    In Visual Basic:

    MyColorPicker.SelectedColor = Colors.Blue

    In C#:

    MyColorPicker.SelectedColor = Colors.Blue;
  2. When your end user selects a color from the Current Color Palette, the Derived Color Palette or the Recent Color Palette.
  3. When your end user hovers over a color from the Current Color Palette, the Derived Color Palette or the Recent Color Palette.
  4. When your end user clicks OK on the advanced editor after selecting a color from there.
Note: After selecting a color using item 1, 2 or 4 from the above list, then that particular color will be added to the Recent Color Palette.

When the dropdown is open and the color editor is visible, you can restore the previous selected color by:

The SelectedColorChanged event is fired when the selected color within the xamColorPicker color is changed. This event receives an argument of type SelectedColorChangedEventArgs where you can determine the new color and the previous color.

The following code snippet demonstrates how to use the SelectedColorChanged event. Note the following snippet assumes you have a RichTextArea control on your page and it sets the selected color to a selected piece of text from the control.


<ig:XamColorPicker x:Name="MyColorPicker"  DerivedPalettesCount="10" 
                   Width="100" Height="20" 
                   SelectedColorChanged="MyColorPicker_SelectedColorChanged"  >

In Visual Basic:

AddHandler MyColorPicker.SelectedColorChanged, AddressOf MyColorPicker_SelectedColorChanged

Private Sub MyColorPicker_SelectedColorChanged(ByVal sender As Object, ByVal e As SelectedColorChangedEventArgs)
   Dim MySelectedColor As New Color
   MySelectedColor = e.NewColor

   rtb.Selection.ApplyPropertyValue(Run.ForegroundProperty, MySelectedColor)
End Sub

In C#:

MyColorPicker.SelectedColorChanged += new EventHandler<SelectedColorChangedEventArgs>(MyColorPicker_SelectedColorChanged);
void MyColorPicker_SelectedColorChanged(object sender, SelectedColorChangedEventArgs e)
   Color MySelectedColor = (Color)e.NewColor;
   rtb.Selection.ApplyPropertyValue(Run.ForegroundProperty, MySelectedColor);

Related Topics

Advanced Editor


Create a Custom Palette