Denis Denis - 9 months ago 90
C# Question

Wpf C# Change checkBox comboboxitem color + disable

I have a list which is populated with a .distinct from other list, then I get these items and create checkboxes to populate a combobox.

After apllying some filter I have to search for these combobox items in a the second list and if it doesn´t exist I have to disable the item and set its background color.

// List to populate the combobox
public List<System.Windows.Controls.CheckBox> ListaCmbMnMe { get; set; }


ListaCmbMnMe = new List<System.Windows.Controls.CheckBox>();

// ListaPendencia is populated from database MnMe is a column from it
foreach (string item in ListaPendencia.Select(p => p.MnMe).Distinct())
checkBox = new System.Windows.Controls.CheckBox();
checkBox.Content = item;


// Just trying to change the properties to find out if it works
foreach (System.Windows.Controls.CheckBox item in ListaCmbMnMe)
item.IsEnabled = false;
item.Background = new SolidColorBrush(Color.FromRgb(102, 153, 255));

cmbMnMe.ItemsSource = ListaCmbMnMe;

I´m doing nothing special on xaml.

Neither the color is changed nor the disable works.

Answer Source

I simply had forgotten to bind the "IsEnabled" property on xaml.