selectedcolor if color selected not in palette

2 posts, 0 answers
  1. Aurore
    Aurore avatar
    58 posts
    Member since:
    Nov 2007

    Posted 29 May 2012 Link to this post


    In a wpf project (3.5), define a colorpicker, a button and a rectangle :
    the rectangle display the color choosen in the colorpicker.
    <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Grid.Row="5">
                <tlk:RadColorPicker x:Name="picker"/>
                <Button Content="Click" Width="40" Height="30" Click="Button2_Click" />
                <Rectangle Width="40"
                           Height="40" Margin="0 10 0 0">
                        <SolidColorBrush Color="{Binding ElementName=picker, Path=SelectedColor}" />

    Select a color (named colorA), the color is well associated in the rectangle.
    Re-open colorpicker, the selectedcolor (dashed line around the latest color choosen) is ok.

    Now click on the button
    private void Button2_Click(object sender, RoutedEventArgs e)
                picker.SelectedColor = Colors.Transparent; //Color.FromArgb(255, 216, 202, 206);// colorB

    I'd like to set the selected color to a color (ColorB) which is not in the main palette.
    The rectangle is ok but Re-open colorpicker, the selectedcolor (dashed line around the latest color choosen) is not ok.
    the dashed line still on the colorA....

    Have you a way to undisplay dash line of previous selected color ?


  2. Petar Mladenov
    Petar Mladenov avatar
    2991 posts

    Posted 01 Jun 2012 Link to this post

    Hello Aurore,

    Currently, there is no straightforward way to remove the selection when you choose a color which is not among the listed colors in the ColorSelector. However , I would suggest you to use ViewModels. Consider having a MainViewModel with collection of MainColors, CurrentPickerColor and  CurrentRectColor properties. These MainColors are bound to the MainColors of the ColorPicker. The Rectangle's fill is bound to the CurrentRectColor property and the ColorPicker's SelectedColor is bound to the CurrentPickerColor  property.
    You can introduce a synchronization logic in the OnPropertyChanged event handlers.
    Another thing that comes up in my mind is that you can use ColorEditor instead of ColorPicker. Is this suitable for you?

    All the best,
    Petar Mladenov
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top