Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

TIP: Change background of WPF Combobox

0.00/5 (No votes)
6 Nov 2012 2  
How to change the popup zone of a WPF Combobox programmatically without restyling
The Background property will just change the edit and drop arrow area of a WPF Combobox.
To change other colors like popup background and highlight color, you have to add some brushes to the resource dictionary, mapping to the system colors:
 
var combo = new Combobox(); 
combo.Background = Brushes.Yellow;
combo.Foreground = Brushes.Blue;
combo.Resources.Add(SystemColors.WindowBrushKey, Brushes.Yellow);
combo.Resources.Add(SystemColors.HighlightBrushKey, Brushes.Red);
 
This is equivalent to XAML code:
 
<Combobox Background="Yellow" Foreground="Blue">
   <Combobox.Resources>
      <SolidColorBrush x:Key="{x:Static SystemColors.WindowBrushKey}" Color="Yellow" />
      <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />
   </Combobox.Resources>
</Combobox>

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here