Search code examples
wpfresourcesbackgroundlistviewitem

Make highlight brush the same as control brush without specifying colour


I want to ensure that a selected ListViewItem's non-focused background is the same as the focused background. I know that the common way of doing this is as follows:

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

However, the problem is that I don't want to specify a colour, I merely want the Brush returned by the static resource whose key is ControlBrushKey to be the same as the one for HighlightBrushKey.


Solution

  • The answer is this:

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