Q:

WPF Databinding making a color selector

Hi I'm having a problem getting my WPF color selector to work. I think its because I'm suing Databinding in a wrong way but im not sure as I dont fully understand it.
What i want is a dropdown, that contains the colors in my list(contains as in shows the actual color not just text).
Heres my Code:
WPF:
<ComboBox Name="cb_farbe" Text="farbe" HorizontalContentAlignment="Center" IsEditable="True" Grid.Row="7" Grid.Column="1" VerticalAlignment="Center" Grid.ColumnSpan="2" Loaded="CbFarbe">

        <ComboBox.ItemTemplate>
            <DataTemplate>
                <Rectangle Grid.Column="0" Margin="5, 10" Fill="{Binding}"/>
            </DataTemplate>
        </ComboBox.ItemTemplate>

    </ComboBox>

c#:
private void CbFarbe(object sender, RoutedEventArgs e)
    {

        List<Color> colors = new List<Color>
        {
           Color.Blue,
           Color.Green,
           Color.LightBlue,
           Color.Black,
           Color.White,
           Color.Gray
        };

        var comboBox = sender as ComboBox;

        comboBox.ItemsSource = colors;

        comboBox.SelectedIndex = 1;

        this.DataContext = colors;

    }

A:

Here's a pure XAML solution. Note that you'll also have to set the width and height of the Rectangle:
<ComboBox SelectedIndex="0">
    <ComboBox.ItemTemplate>
        <DataTemplate>
            <Rectangle Margin="5,10" Width="20" Height="20" Fill="{Binding}"/>
        </DataTemplate>
    </ComboBox.ItemTemplate>
    <SolidColorBrush>Blue</SolidColorBrush>
    <SolidColorBrush>Green</SolidColorBrush>
    <SolidColorBrush>LightBlue</SolidColorBrush>
    <SolidColorBrush>Black</SolidColorBrush>
    <SolidColorBrush>White</SolidColorBrush>
    <SolidColorBrush>Gray</SolidColorBrush>
</ComboBox>

Note that the ComboBox's SelectedItem property would return a SolidColorBrush. If you actually want to have a Color, set
<ComboBox ... SelectedValuePath="Color">

and get the color by the SelectedValue property.

