.NET 4.0 ListView control lose foreground color with Windows Classic theme

Aug 15, 2011 at 10:03 PM

I have a listview with a style set on the ListViewItem.  The style contains a series of DataTriggers that determine the foreground color of the listviewitem -- changing it from blue to red depending on the trigger.  It works beautifully until I change the theme to Windows Classic (which I must support -- and it MUST have a similar look and feel -- so no changing the Highlight color).

With Windows Classic, my listview displays perfectly with its red and blue items depending on my data triggers.

When a listviewitem is selected, it disregards my datatriggers and it changes the foreground color to white so that I can see it through the navy blue selection color that Windows Classic uses.  The problem is, when I unselect the item (by clicking on something else), it resets the foreground color of the listview item to black. It loses its red or blue foreground color that was determined by the datatrigger.  When a listview item is unselected with Windows Classic, how can I get the foreground color to automatically go back to the color that it was prior to selection? 

If the answer is, you can't...Then I can change the selection color to something lighter, such as beige.  I have tried the following -- but it does not solve the problem when the item becomes unselected. Furthermore, when it is selected, the foreground is not working reliably. I suspect that I am poking in the right area...but not sure how to bind to the current item...This is a single select listview.

 <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                            Color="Beige" />
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}"
                            Color="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Foreground}" />

            </Style.Resources>

 

 

Aug 24, 2011 at 3:29 PM

The problem -- was that when I said: "a listviewitem is selected, it disregards my datatriggers and it changes the foreground color to white so that I can see it through the navy blue selection color that Windows Classic uses", the datatriggers had <ColorAnimation>.  This worked fine until I got to the WindowsClassic theme...Once I backed out the color animation for WindowsClassic, everything was fine.