How Can I Override the Highlight (Mouse Over) Color For a GridView's / ListView's Headers?
-
Tuesday, June 30, 2009 10:01 PMI have tried the following code...
<ListView.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Orange" />
</ListView.Resources>
in the listview. Also tried it in...
<GridView.ColumnHeaderContainerStyle>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Orange" />
</GridView.ColumnHeaderContainerStyle>
Why is this not overriding the default (Light Blue Glass in Windows 7) highlight brush? Shouldn't the headers be Orange instead when I mouse over them?
Also, I am only interested in overriding the highlight brush, I do not want to redesign the entire control template. Please advise how to get this to work.
Thanks!
All Replies
-
Wednesday, July 01, 2009 2:40 PMOkay, here is a URL to a screenshot of the problem...
http://brillyant.com/sample.jpg
...as you can see I am using a black background for my gridview headers. But when a user mouses over one of the headers it looks like cra_p. What I must figure out how to do is remove the light blue glass effect and replace it with a simple gray color.
WHY IS THIS SO FREAKIN' IMPOSSIBLE?!! :) (sorry) I'm just trying to change one color for crying out loud...
Anyways, as more involved approach, I decided to explore replacing the control template as a possible solution. But when I opened the project in Blend (to use the "Edit a copy" of the control template functionality), in the visual tree Blend does not recognize anything below the ListView control itself? And so I have no idea what the GridViewHeader's default control template looks like...assuming that is the template that I need to change.
So, hasn't anyone out there tried to do something like this before? How can achieve the desired results? -
Monday, July 06, 2009 1:58 PMOkay, I'm assuming this just cannot be done. I find that hard to believe...?
-
Monday, July 06, 2009 2:47 PM
Try using the following snippet to view the ControlTemplate. Get the GridViewHeader object you are trying to look at and override, and pass its .ControlTemplate object to this function. It will return the XAML as a string. You can use this to create a new control template. You can then use a Style that assigns the Template to either the specific headers you are looking to modify OR all controls of the specififed type (by setting the Target Type property and omitting the x:Key attribute).
private string GetTemplateString(FrameworkTemplate template) { if (template != null) { // Create XmlWriter Settings. We need the XmlWriter for // the XamlWriter.Save() call XmlWriterSettings settings = new XmlWriterSettings(); // Shows User-Friendly XML output with indents (tabs, sp, etc.) settings.Indent = true; // use space character 4 times for the tab. \t settings.IndentChars = new string(' ', 4); // Shows all attributes as new lines settings.NewLineOnAttributes = true; // StringBuilder to act as output container StringBuilder strbuild = new StringBuilder(); // Create the XmlWriter from the settings, // using the StringBuilder as output container XmlWriter xmlwrite = XmlWriter.Create(strbuild, settings); try { // Try writing the ControlTemplate XAML to the XmlWriter, // which populates the StringBuilder downstream XamlWriter.Save(template, xmlwrite); // Return the StringBuilder text return strbuild.ToString(); } catch (Exception exc) { // Display Exception that occurs return "EXCEPTION: " + exc.Message; } } else { // Template is null return "Template is [null]"; } }
John Angelini
Leader/Founder
Philly XAML.org
The Philadelphia XAML Developers Group
If this response answers your post or is helpful, please mark it as such.
Some of us rely on these answers for things like achieving MVP status. Thanks.- Marked As Answer by Jim Zhou - MSFT Tuesday, July 07, 2009 1:23 PM
- Edited by John Angelini MVP Friday, July 17, 2009 4:09 PM
-
Thursday, September 13, 2012 7:32 PM
The XAML you are looking for is found here:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/cdce635f-8054-4bf1-b217-8c065d7341e2
Just paste it into your Theme and tweak the colors/gradients. It took me forever to find this example. It's a lot of XAML but it works and it's easy to implement.
- Proposed As Answer by MurrayRobert1 Thursday, September 13, 2012 7:34 PM
- Edited by MurrayRobert1 Thursday, September 13, 2012 7:38 PM

