How to set the background color of a checkbox's content by binding in WPF

checkbox, styling, wpf

Solution

Try this:

<ListBox Name="ListBox1" ItemsSource="{Binding Path=relationshipTypesTable.dataTable.DefaultView}">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Horizontal"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>

    <ListBox.ItemTemplate>
        <DataTemplate>
            <CheckBox IsChecked="True">
                <TextBlock Text="{Binding typeDesc}" Background="{Binding color}"/>
            </CheckBox>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

Problem

I am trying to figure out how to bind the background color of the content for a checkbox. Here is the code I have, of course the background setting just changes the color of the checkbox not the color behind the text. ``` <ListBox Name="ListBox1" ItemsSource="{Binding Path=relationshipTypesTable.dataTable.DefaultView}"> <ListBox.ItemsPanel> <ItemsPanelTemplate> <StackPanel Orientation="Horizontal"/> </ItemsPanelTemplate> </ListBox.ItemsPanel> <ListBox.ItemTemplate> <DataTemplate> <CheckBox IsChecked="True" Content="{Binding typeDesc}" Background="{Binding color}"/> </DataTemplate> </ListBox.ItemTemplate> </ListBox> ```

Original source