开发者

Make highlight brush the same as control brush without specifying colour

开发者 https://www.devze.com 2023-01-16 17:42 出处:网络
I want to ensure that a selected ListViewItem\'s non-focused background is the same as the focused backgrou开发者_Python百科nd.I know that the common way of doing this is as follows:

I want to ensure that a selected ListViewItem's non-focused background is the same as the focused backgrou开发者_Python百科nd. 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.


The answer is this:

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消