gpt4 book ai didi

.net - WPF ListView 非事件选择颜色和元素字体颜色

转载 作者:行者123 更新时间:2023-12-03 20:19:48 27 4
gpt4 key购买 nike

我可以设置 ListView 非事件选择颜色

我使用了以下问题中描述的解决方案

WPF ListView Inactive Selection Color

我需要更改所选非事件元素的字体颜色,有没有简单的方法来实现这一点?

谢谢你

最佳答案

不幸的是,您不能使用 SystemColors.ControlTextBrushKey,因为它适用于未选择项目或已选择但未激活的项目(您的问题读起来好像您只对后者感兴趣)。但是,您可以这样做:

<ListBox ...>
<ListBox.Resources>
<!-- this customizes the background color when the item is selected but inactive -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}">Red</SolidColorBrush>
</ListBox.Resources>
<ListBox.ItemContainerStyle>
<Style>
<Style.Triggers>
<!-- this customizes the foreground color when the item is selected but inactive -->
<Trigger Property="Selector.IsSelected" Value="True">
<Setter Property="TextElement.Foreground" Value="Blue"/>
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>

关于.net - WPF ListView 非事件选择颜色和元素字体颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/793937/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com