I spend almost two hours for something which turned out very simple. However, as always, would like save someone else’s time who trying to do the same.

All I wanted to do is the change the foreground and background colour of SelectedItem of TreeView control. The native WPF treeview control. I tried various styles but didn’t work. Didn’t work with triggers as well. Finally i discovered that Treeview uses system colours for its highlighting of SelectedItem. Hence, in the control template of treeview, it was using {x:Static SystemColors.HighlightBrushKey} and  {x:Static SystemColors.HighlightTextBrushKey} for Background and Foreground. So any styling done didn’t seem to apply easily and there is also no built-in property for treeview like SelectedItemStyle. Finally I had to grab these static objects and set them manually in resources section to my own colours to make it to work. This is what I did:


<SolidColorBrush x:Key=”{x:Static SystemColors.HighlightBrushKey}” Color=”White”/>

<SolidColorBrush x:Key=”{x:Static SystemColors.HighlightTextBrushKey}” Color=”Black”/>


This did the trick and worked. However, it ended up overriding the system settings for colour so had to set it back to its default for it to no disturb anything else by doing:


<SolidColorBrush x:Key=”{x:Static SystemColors.HighlightBrushKey}” Color=”DarkBlue”/>

<SolidColorBrush x:Key=”{x:Static SystemColors.HighlightTextBrushKey}” Color=”White”/>


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s