This project has moved and is read-only. For the latest updates, please go here.

Cannot bind ColorPicker SelectedColor to the ViewModel

Apr 28, 2013 at 8:27 PM
I am trying to do a simple binding on the SelectedColor property of a ColorPicker. I created a simple app to demo my issue.

The XAML:
<Window x:Class="XceedColorPickerTest.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:XceedColorPickerTest"
        xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
        Title="MainWindow" Height="350" Width="525">
    <Window.DataContext>
        <local:MainWindowViewModel />
    </Window.DataContext>

    <StackPanel>

        <xctk:ColorPicker SelectedColor="LightBlue" 
                          ShowDropDownButton="True" 
                          DisplayColorAndName="True" />

        <TextBlock Text="{Binding TestBrush}"/>
        <xctk:ColorPicker SelectedColor="{Binding TestBrush}" 
                          ShowDropDownButton="True" 
                          DisplayColorAndName="True" />

        <TextBlock Text="{Binding TestBrush2}"/>
        <xctk:ColorPicker SelectedColor="{Binding TestBrush2}" 
                          ShowDropDownButton="True" 
                          DisplayColorAndName="True" />

    </StackPanel>
</Window>

The VM:
using System;

namespace XceedColorPickerTest
{
    public class MainWindowViewModel
    {
        public MainWindowViewModel()
        {
            TestBrush = System.Windows.Media.Brushes.Red;
            TestBrush2 = System.Windows.Media.Brushes.Green;
        }

        public System.Windows.Media.Brush TestBrush { get; set; }
        public System.Windows.Media.SolidColorBrush TestBrush2 { get; set; }

    }
}
First ColorPicker works as expected. But neither binding in the following two to either TestBrush and TestBrush2 work. They DO work with the TextBlocks which cast the brushes to "#FFFF0000" and "#FF008000", respectively (its not a notification thing as far as I can tell).

Thanks
Ernie
Apr 29, 2013 at 8:50 PM
Forget it. I got it. I had to use a Media.Color (and a System.Background.Color will not work either). Like this:
    public System.Windows.Media.Color MediaColor { get; set; }
Ernie