Set SelectedColor value at load time

Oct 6, 2011 at 12:04 PM

Any idea of setting the color value to the color picker.

For example i want to set the color Red as default selected color and  i tried this code

   colorBack.SelectedColor = System.Windows.Media.Colors.Red;

but is not working.When the page loads it seems that White color is selected as  default

Thanks

Jibin

Jul 19, 2016 at 6:47 PM
This is a super old question, but I just found this project and ran into the same problem. It's easy to fix, you just need to modify the CustomColorPicker.xaml.cs file. Change this:
String _hexValue = string.Empty;
public String HexValue
{
    get { return _hexValue; }
    set { _hexValue = value; }
}

private Color selectedColor = Colors.Transparent;
public Color SelectedColor
{
    get { return selectedColor; }
    set
    {
        if (selectedColor != value)
        {
            selectedColor = value;
        }
    }
}
To this:
private String _hexValue = string.Empty;
public String HexValue
{
    get { return _hexValue; }
    set
    {
        _hexValue = value;

        var newColor = ColorTranslator.FromHtml(HexValue);
        recContent.Fill = new SolidColorBrush(Color.FromArgb(newColor.A, newColor.R, newColor.G, newColor.B));
    }
}

private Color selectedColor = Colors.Transparent;
public Color SelectedColor
{
    get { return selectedColor; }
    set
    {
        if (selectedColor != value)
        {
            selectedColor = value;
        }

        recContent.Fill = new SolidColorBrush(selectedColor);
    }
}