DNF

Im building my own combobox C I wrote datatemplate for items connected to combobox but I have a problem with item highlighting. When mouse is over some combobox item it's background is highlighted on blue and I dont want this. I tried to write custom controltemplate for combobox and custom ItemsPanelTemplate but I still dont know how to get over this highlight C can somebody help me with this stupid little thing



Re: Windows Presentation Foundation (WPF) How to change highlight color in popup of combobox ??

Szymon Kobalczyk

Hi,

I run into same problem recently using ListBox and I got around it by overriding the HighlighBrush and ControlBrush system colors for this particular UserControl. Place following in your controls resources dictionary and set appropriate colors:

<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="#FFE89519" />

<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="#FFE89519" />

If you create style for your comboboxes you can also override it for this style.

I belive this is where I got this idea from: http://www.beacosta.com/2006/05/how-can-i-change-way-data-_114702952170041155.html

Hope this helps,

Szymon





Re: Windows Presentation Foundation (WPF) How to change highlight color in popup of combobox ??

Szymon Kobalczyk

Today I've posted a bit longer explanation on my blog: http://geekswithblogs.net/kobush/archive/2007/03/25/109753.aspx





Re: Windows Presentation Foundation (WPF) How to change highlight color in popup of combobox ??

MatthiasXaml

The best way to do it is to do the following...

If you are in Blend, highlight your combobox and, from the Object menu, click "Edit other styles" --> "Edit ItemContainerStyle" --> "Edit a Copy"

This will toss you in an ItemContainerStyle editing mode. Right click on the "ItemContainterStyle" in the "Objects and Timeline" section and click "Edit Control Parts (Template)" --> "Edit a Copy"

In the "Triggers" section, you'll see two property triggers. Click on the "IsHighlighted = True" and you will see that the border section of the template will turn blue (the default highlight brush).

Simply change the background to anything you want.

From a XAML point of view this looks like:

<ComboBox ... ItemContainerStyle="{DynamicResource MyItemStyle}">

which points to:

<Style x:Key="MyItemStyle" TargetType="{x:Type ComboBoxItem}">

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="{x:Type ComboBoxItem}">

<Border x:Name="Bd" Background="{TemplateBinding Background}">

<ContentPresenter />

</Border>

<ControlTemplate.Triggers>

<Trigger Property="IsHighlighted" Value="true">

<Setter Property="Background" TargetName="Bd" Value="#[Whatever Value I Want" />

<Setter Property="Foreground" Value="#[Whatever Value I Want]"/>

</Trigger>

</ControlTemplate.Triggers>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

This solution will also work for changing the highlighting for a TreeView, a ListBox and a ListView.

I posted pretty much the same thing (except with pretty pictures) at my blog.





Re: Windows Presentation Foundation (WPF) How to change highlight color in popup of combobox ??

alainkkk

hi.. great post..

but i canot do it in my listview..

Object menu, click "Edit other styles" --> "Edit ItemContainerStyle" --> "Edit a Copy"

i cannot click on the " edit a copy" .. it is visible.. but canot click.






Re: Windows Presentation Foundation (WPF) How to change highlight color in popup of combobox ??

MatthiasShapiro

If "Edit a Copy" is not active, it means that there is currently no active ItemContainerStyle for your listView (and WPF will probably end up using the Aero theme as a default if you're working in Vista).

Go ahead and click on "Create Empty" and that will at least give you a style to work with as a starting point. From within that style, you can right click on the style and go to "Edit Control Parts (Template) -> Edit a Copy..." to get to a copy of the actual ItemContatinerStyle template (along with all the default triggers and layout information).





Re: Windows Presentation Foundation (WPF) How to change highlight color in popup of combobox ??

alainkkk

cool.. how do i mouseover the listview data.. and these effect will be shown row by row..

currently the effect only show when i click on the data..






Re: Windows Presentation Foundation (WPF) How to change highlight color in popup of combobox ??

MatthiasShapiro

You can do it one of two ways.

The first is to go into your ItemContainerStyle and give it a property trigger (the "+ Property" button in the triggers section). Change the trigger to "IsMouseOver = True" and change the background or whatever you want to change.

If you need more specific control than that (and I find I often do) you can go to the ItemContainerStyle template and do the same thing there. Make sure you place the trigger on the highest level in the visual tree that you can. But once you have the trigger in place in the template, you can change anything... the color, the margins, the width... whatever you want.

Just a reminder, placing a trigger in the style will be simpler and you should toy with having the trigger there before you put it in the template.

Good luck!





Re: Windows Presentation Foundation (WPF) How to change highlight color in popup of combobox ??

alainkkk

hi i am able to apply your effect into my combobox...

but not to my listview.. after i create empty in the edititemcontainerstyle.. and do those following step..

when i run my program.. the listview display " system.data.datarowview" instead of any value.. pls help