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

In WPF telerik control RadColorPicker, can't apply black color, if the color already selected is null

1 Answer 187 Views
ColorPicker
This is a migrated thread and some comments may be shown as answers.
Randeep
Top achievements
Rank 1
Randeep asked on 16 Jul 2015, 06:14 PM

We are using WPF telerik control RadColorPicker. In the beginning, we choose to set null color for the entity. The problem is, this null color is being treated as black color by the RadColorPicker and so we can't apply a black color immidiately. Refer to the working code below

XAML:

<telerik:RadColorPicker x:Name="radColorPicker" IsRecentColorsActive="True" SelectedColor="{Binding Path=MyColor}" SelectedColorChanged="radColorPicker_SelectedColorChanged">
<telerik:RadColorPicker.ContentTemplate>
<DataTemplate>
<Rectangle MinWidth="40" MinHeight="20">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding ElementName=radColorPicker, Path=SelectedColor, Mode=TwoWay}"/>
</Rectangle.Fill>
</Rectangle>
</DataTemplate>
</telerik:RadColorPicker.ContentTemplate>
</telerik:RadColorPicker>

Code Behind/View Model:

public Window9()
{
InitializeComponent();
this.DataContext = this;

MyColor = null; // I can't apply a black color in this case because null is being treated as black color
//MyColor = "Red"; // I can apply a black color, when the already applied color is red.
}

private void radColorPicker_SelectedColorChanged(object sender, EventArgs e)
{
MessageBox.Show("Color changed!");
}

public string MyColor { get; set; }

 

However, if I would choose some other color than black, say Red, then after that I am able to apply a black color or if we by default set a red color first as shown in the code, then also we would be able to set a black color.
How to make RadColorPicker treat null color as null only and not black, so that we can apply black color immidiately.​

 

1 Answer, 1 is accepted

Sort by
0
Petar Mladenov
Telerik team
answered on 20 Jul 2015, 07:47 AM
Hi Randeep,

You are binding the SelectedColor property (of type Color) of the RadColorPicker to string property from your Main View.
The built-in WPF converters kick in because of the XAML binding you use and convert the string.Empty and the null to Black Color. However, to better represent null color I would suggest the following:

-instead of string in the model, use Color:
public Color MyColor { get; set; }
- initialize the start color with this contructor:
MyColor = Color.FromArgb(0, 0, 0 , 0);

This way when you change the color to black runtime, the SelectedColor will be successfully set to Black.

Regards,
Petar Mladenov
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
ColorPicker
Asked by
Randeep
Top achievements
Rank 1
Answers by
Petar Mladenov
Telerik team
Share this question
or