Changing background color of some rows in a combobox

Wayne In Yak

I have a bound combobox and depending on the values I get back in the records I want to change the background color of certain rows in the combobox. Is this possible and if so how?

A little more clarification. I'm looking at one of the fields in each row and based on its value I want to change the background color. So I could be changing all of the row, some of the rows, or none of the rows.

Thanks

McGarnagle

Use the ItemContainerStyle to set the item background color per-row. You can bind to a property in the row's data context, and use an IValueConverter to get the appropriate brush. Eg, assuming that the items have a property "Y":

<ComboBox>
    <ComboBox.Resources>
        <local:BoolToBrushConverter x:Key="BoolToBrushConverter" />
    </ComboBox.Resources>
    <ComboBox.ItemContainerStyle>
        <Style TargetType="ComboBoxItem">
            <Setter Property="Background" 
                    Value="{Binding Y,Converter={StaticResource BoolToBrushConverter}}" />
        </Style>
    </ComboBox.ItemContainerStyle>
</ComboBox>

Then the "BoolToBrushConverter" would be something like this:

public class BoolToBrushConverter: IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return (value as bool? == true) ? Brushes.Green : Brushes.Red;
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

NG Style not changing background color

From Dev

Changing the background color of a Button in Kivy

From Dev

Changing HighCharts background color?

From Dev

Changing Background Color in Rstudio

From Dev

Changing background color with setInterval

From Dev

Changing background color of a div based on background color of some other div

From Dev

Changing Background Color of UILabel

From Dev

Changing the background color of an EditText issue

From Dev

WPF Change Background color of a Combobox

From Dev

Changing the Background color for post in Blogspot?

From Dev

Android ActionBar not changing background color

From Dev

Changing Bootstrap active table rows background color

From Dev

Onsen toolbar background color not changing

From Dev

Changing background color of WebView JavaFX

From Dev

Background color changing tiles

From Dev

Changing the row background color of DataGridView

From Dev

Changing background color of glyphicon in Bootstrap

From Dev

Android Button background color not changing

From Dev

Changing background color with addClass in jQuery

From Dev

Changing background color on scrollable listview

From Dev

Div Background Color not changing

From Dev

Changing background color in a activity.

From Dev

Changing background color of a div based on background color of some other div

From Dev

Background color is not changing in DataTrigger

From Dev

HTML background color not changing

From Dev

Changing background color of SignatureView

From Dev

Changing background color of Frame

From Dev

Textfield background color not changing

From Dev

changing the combobox cell background in datagridview

Related Related

HotTag

Archive