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

2 posts, 0 answers
  1. Randeep
    Randeep avatar
    3 posts
    Member since:
    Jul 2015

    Posted 16 Jul 2015 Link to this post

    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


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

    Code Behind/View Model:

    public Window9()
    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.​


  2. Petar Mladenov
    Petar Mladenov avatar
    3095 posts

    Posted 20 Jul 2015 Link to this post

    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.

    Petar Mladenov
    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
Back to Top