gpt4 book ai didi

wpf - 列表框:选定的项目未突出显示

转载 作者:行者123 更新时间:2023-12-04 13:52:49 24 4
gpt4 key购买 nike

在我的 WPF 应用程序中,我有一个简单的列表框:

                 <ListBox x:Name="lbUtilities">
<ListBoxItem Tag="2" Content="One" IsSelected="True" />
<ListBoxItem Tag="5" Content="Two" />
</ListBox>

问题是当 ListBox 第一次出现时,所选项目(“一个”)没有突出显示。如果我单击任何项​​目,它会突出显示。如何让默认选择的项目突出显示为系统颜色?

谢谢。

最佳答案

它已被选中,但您需要突出显示未聚焦的

<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 - 列表框:选定的项目未突出显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17725488/

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