Cat*_*top 3 wpf highlight systemcolors
我正在尝试创建一个ListBox,其中突出显示的项目看起来是相同的,无论ListBox是否具有焦点.
基本上我想将SystemColors.ControlBrushKey颜色属性设置为与SystemColors.HighlightBrushKey颜色相同.
我以为我可以使用以下内容:
<ListBox>
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
</ListBox.Resources>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
但这实际上会引发以下错误:
System.Windows.Markup.XamlParseException:设置属性'System.Windows.Media.SolidColorBrush.Color'引发异常.---> System.ArgumentException:'#FF3399FF'不是属性'Color'的有效值
如果我设置Color="#FF3399FF"它工作正常.
我究竟做错了什么?
感谢Nicholas W指出我正确的方向 - 这里是ListBox的完整代码:
<ListBox Width="200" Height="200">
<ListBox.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" />
</ListBox.Resources>
<ListBox.ItemContainerStyle>
<Style>
<Style.Triggers>
<Trigger Property="Selector.IsSelected" Value="True">
<Setter Property="TextElement.Foreground" Value="White"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
<ListBoxItem IsSelected="True">Item A</ListBoxItem>
<ListBoxItem>Item B</ListBoxItem>
<ListBoxItem>Item C</ListBoxItem>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5443 次 |
| 最近记录: |