views:

54

answers:

2

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.

+1  A: 

Try this... I know it works to set two properties to match, not sure if it will work in your context, but it's worth a shot:

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

I tested this using a TextBox as a playground. I'm not sure of your exact application, but here was my test markup:

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

This just set the background to blue, and the foreground to the background, which was the expected result.

md5sum
It doesn't work. Try the following and you'll see what I mean. Select an item from the ListView, then click on the TextBox. <Grid> <Grid.RowDefinitions> <RowDefinition /> <RowDefinition /> </Grid.RowDefinitions> <ListView> <ListView.ItemContainerStyle> <Style TargetType="ListViewItem"> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Blue"/> <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="{DynamicResource SystemColors.HighlightBru
Chris
A: 

The answer is this:

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

Depressingly easy, really.

Chris