views:

2579

answers:

2

Hello!

I need to change the highlight color of a ComboBox's selected item in the popup list. I've found several tutorials explaining how to do this, but all of them either use Blend, which I do not have and cannot obtain, or involve changing the system default colors--which seems like a hack to me.

Can someone point me to the template I need to override, or tell me the property I need to set?

Thanks!

+4  A: 

Override the SystemColors.HighlightBrushKey (and SystemColors.HighlightTextKey if you want):

<ComboBox>
 <ComboBox.Resources>
  <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}">Red</SolidColorBrush>
 </ComboBox.Resources>
 <ComboBoxItem>One</ComboBoxItem>
 <ComboBoxItem>Two</ComboBoxItem>
</ComboBox>

HTH, Kent

Kent Boogaart
Once again, isn't there a way to do this that doesn't involve changing the system colors?
Klay
I keep finding references to a SelectionBoxItemTemplate. Is this what controls the highlighted item in the popup?
Klay
You're not changing the system colors - you're merely overriding them at the scope of the ComboBox.
Kent Boogaart
I guess I'm looking for the template I would change, as it seems like that would be the "correct" way to do it. Would this work for setting the brush to be a gradient? What if I wanted to display an icon next to the selected item?In any case, I do appreciate the help.
Klay
The "correct" way depends on exactly what you're trying to achieve ;) It is the ComboBoxItem template that reaches out and grabs these brush resources, so you would have to re-template that if you decide to go that route. Any brush (including gradient) can be used in the example above. If you want your icon outside the bounds of the selection box you could probably fudge a solution without re-templating but re-templating would be the better solution.
Kent Boogaart
Sorry to ask so many questions, but how do I include your XAML in a ControlTemplate for the ComboBox? I can't seem to figure out how to include a resources section in which to put it.
Klay
A: 

I have created a template for Combobox here :

http://wpfstyles.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=31388#DownloadId=78720

Thanks, Vikas

Vikas bhandari