WPF ListBox未显示选择突出显示 [英] WPF ListBox not showing selection highlight

查看:328
本文介绍了WPF ListBox未显示选择突出显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能为我的生活指责为什么我没有在我的列表框中获得选择突出显示。没有合并的资源字典,并且在父资源中没有定义样式ovverrides。



选择似乎有用(它正在做我应该做的事情选择),但列表框没有突出显示所选项目(无论列表框是聚焦还是未聚焦)。



我甚至试图专门设置列表框的容器项目强迫颜色的样式。



有人可以告诉我要找什么吗?

解决方案

< pre lang =xml>它已被选中,但你需要一个没有聚焦的高光

< ListBox Grid.Row = 0 x:名称 = lbUtilities >
< ListBox.ItemContainerStyle >
< 样式 TargetType = ListBoxItem >
< Style.Triggers >
< 触发器 属性 = IsSelected = True < span class =code-attribute> >
< < span class =code-leadattribute> Setter Property = FontWeight = 粗体 / >
< Setter Property = 背景 = 透明 / >
< Setter 属性 = 前景 = < span class =code-keyword>黑色
/ >
< / Trigger >
& lt; / Style.Triggers >
< Style.Resources >
< SolidColorBrush x:键 = {x:Static SystemColors.HighlightTextBrushKey} 颜色 = 黑色 / >
<! - 焦点时所选项目的背景 - >
< SolidColorBrush x:键 = {x:静态SystemColors。 HighlightBrushKey} 颜色 = LightCyan / >
<! - 未聚焦时所选项目的背景 - >
< SolidColorBrush x:Key = {x:Static SystemColors.ControlBrushKey} 颜色 = LightGray / >
< / Style.Resources >
< / Style >
< / ListBox.ItemContainerStyle >
< ListBoxItem 标记 = 2 内容 = 一个 IsSelected < span class =code-keyword> =
True / >
< ListBoxItem 标记 = 5 内容 = 两个 / >
< / ListBox >


I can't for the life of me finger out why I'm not getting a selection highlight in my listboxes. There are no merged resource dictionaries, and there are no style ovverrides defined within parent's resources.

Selection appears to work (it's doing what it's supposed to do when I make a selection), but the listbox isn't highlighting the selected item (regardless of whether the listbox is focused or unfocused).

I even tried specifically setting the listbox's container item style to force a color.

Can someone please tell me what to look for?

解决方案

It is selected but you need a hightlight for not focused

<ListBox Grid.Row="0" x:Name="lbUtilities">
    <ListBox.ItemContainerStyle>
        <Style TargetType="ListBoxItem">
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="True" >
                    <Setter Property="FontWeight" Value="Bold" />
                    <Setter Property="Background" Value="Transparent" />
                    <Setter Property="Foreground" Value="Black" />
                </Trigger>
            </Style.Triggers>
            <Style.Resources>
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black"/>
                <!-- Background of selected item when focussed -->
                <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightCyan"/>
                <!-- Background of selected item when not focussed -->
                <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="LightGray" />
            </Style.Resources>
        </Style>
    </ListBox.ItemContainerStyle>
    <ListBoxItem Tag="2" Content="One" IsSelected="True"/>
    <ListBoxItem Tag="5" Content="Two" />
</ListBox>


这篇关于WPF ListBox未显示选择突出显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆