Answered by:
Overriding Default Vista Gradient / Glow Effects For Controls

Question
-
I have a ListView where I change the background of items as the mouse passes over them. I use an ListView.ItemContainerStyle and the following XAML for this...
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Foreground" Value="#ffffffff"/>
<Setter Property="Background" Value="#ff000000"/>
</Trigger>
When I run it on Windows XP, everything works as expected. As the mouse passes over the items, they change to have a black background and white text.
Something stranges happens, however, when I run it on Windows Vista. The colors remain the same, but the item background has an added gradient with the upper 1/4 or so of the item colored slightly different. As a result some of the text is difficult to read. Also, the item appears to "glow" for no apparent reason.
Now, if I have taken the time to specify a trigger to style my listview items, why does Windows Vista change it!!!???
Oh yeah, the same happens with Button controls. I don't like this. Please tell me how I can stop this from happening.
Thursday, November 20, 2008 2:55 PM
Answers
-
Hi,
Certain controls have styles defined. You must override them or use their parent control styles to remove the extra styling you do not need.
For example for ListView you can fallback to ListBox to remove a lot of the style. Just use:<ListView.Resources> <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"/> </ListView.Resources>
Most of the effects will be gone, then in that same Style tag you can add the new ones you want.
Also for the Button, you can use ButtonBase.
Hope this helps.
-noorbakhsh
- Proposed as answer by noorbakhsh Thursday, November 20, 2008 4:38 PM
- Marked as answer by Jim Zhou - MSFT Wednesday, November 26, 2008 10:03 AM
Thursday, November 20, 2008 4:37 PM -
Windows Vista is "changing it" because writing visual effects is a lot harder than you seem to think it is. Every theme in every supported Windows operating system (that's about six themes) has its own complex visual styles and triggers for every control. It just so happens that the Vista template overlays a Vista-style shine to the background color of a button. You can't do anything about that without writing your own template.
If you want to change the way a control behaves on mouse over, you need to be writing your own templates. You can do this just once for each control, unless you want your templates to tie in with the rest of the operating system (which you really should), in which case you'll need to write six styles/templates. Writing templates for controls is involved because you need to handle all operating system themes and you'll have to re-release your software to use the Windows 7 theme when that is released.
Controls for WPF and Windows Forms at http://www.divelements.co.uk- Marked as answer by Jim Zhou - MSFT Wednesday, November 26, 2008 10:03 AM
Thursday, November 20, 2008 5:17 PM
All replies
-
Hi,
Certain controls have styles defined. You must override them or use their parent control styles to remove the extra styling you do not need.
For example for ListView you can fallback to ListBox to remove a lot of the style. Just use:<ListView.Resources> <Style TargetType="{x:Type ListViewItem}" BasedOn="{StaticResource {x:Type ListBoxItem}}"/> </ListView.Resources>
Most of the effects will be gone, then in that same Style tag you can add the new ones you want.
Also for the Button, you can use ButtonBase.
Hope this helps.
-noorbakhsh
- Proposed as answer by noorbakhsh Thursday, November 20, 2008 4:38 PM
- Marked as answer by Jim Zhou - MSFT Wednesday, November 26, 2008 10:03 AM
Thursday, November 20, 2008 4:37 PM -
Windows Vista is "changing it" because writing visual effects is a lot harder than you seem to think it is. Every theme in every supported Windows operating system (that's about six themes) has its own complex visual styles and triggers for every control. It just so happens that the Vista template overlays a Vista-style shine to the background color of a button. You can't do anything about that without writing your own template.
If you want to change the way a control behaves on mouse over, you need to be writing your own templates. You can do this just once for each control, unless you want your templates to tie in with the rest of the operating system (which you really should), in which case you'll need to write six styles/templates. Writing templates for controls is involved because you need to handle all operating system themes and you'll have to re-release your software to use the Windows 7 theme when that is released.
Controls for WPF and Windows Forms at http://www.divelements.co.uk- Marked as answer by Jim Zhou - MSFT Wednesday, November 26, 2008 10:03 AM
Thursday, November 20, 2008 5:17 PM -
So I will need is just these three lines of code? I am only asking because I cannot test on Vista until tomorrow. The problem does not manifest itself when using Windows XP (normal development machine).Thursday, November 20, 2008 5:54 PM
-
Well I don't like the extra styles in certain places either, so I just add those lines of code for that ListView or Button and I am on Vista,
Of course, you can do a global or page by putting the Style tag in the Resource section of the Window (or any other control) or in the Generic.xaml in the themes folder to be applied globally!
I hope that it is what you are looking for.
-noorbakhsh
Thursday, November 20, 2008 9:23 PM