This is a migrated thread and some comments may be shown as answers.

selectedcolor if color selected not in palette

1 Answer 102 Views
ColorPicker
This is a migrated thread and some comments may be shown as answers.
Aurore
Top achievements
Rank 1
Aurore asked on 29 May 2012, 11:46 AM
Hello,

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">
                <Rectangle.Fill>
                    <SolidColorBrush Color="{Binding ElementName=picker, Path=SelectedColor}" />
                </Rectangle.Fill>
            </Rectangle>
        </StackPanel>

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 ?

Regards
Aurore

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 01 Jun 2012, 08:18 AM
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 >>

Tags
ColorPicker
Asked by
Aurore
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or