Dorra Tayâa

Dorra Tayâa

  • NA
  • 3
  • 4.7k

combobox background programmatically

Aug 7 2014 6:26 AM
hello please i'm trying to change color of combobox itry with backgroun property
combo.Background= (Brush)new BrushConverter().ConvertFrom("#FEFCD7"); 
but just border changed 
i even try to reach all component inside the combo via VisualTreeHelper and i find that it's composed of Grid then togglebutton and contentPresenter then under the contentpresenter there is textblock i try to change the textblock background but it doesn't work also the grid background but no result 
DependencyObject child = VisualTreeHelper.GetChild(combo, 0);
(child as Grid).Background = (Brush)new BrushConverter().ConvertFrom("#FEFCD7");
int x = VisualTreeHelper.GetChildrenCount(child);
List<DependencyObject> childs = new List<DependencyObject>();
for (int i = 0; i < x; i++)
{
DependencyObject child2=VisualTreeHelper.GetChild(child, i);
childs.Add(child2);
if (child2.GetType() == typeof(ContentPresenter))
{
DependencyObject child3 = VisualTreeHelper.GetChild(child2, 0 );
int c = VisualTreeHelper.GetChildrenCount(child2);
(child3 as TextBlock).Background = Brushes.Transparent;
(child3 as TextBlock).Background = (Brush)new BrushConverter().ConvertFrom("#FEFCD7");
}
}
please i don't want to change highlightind just the background ,  i'm using the win8 theme for all my windows 
 

Answers (1)