LISTBOX.SelectedIndex选中条目后什么让条目变颜色
时间: 2024-02-07 19:02:17 浏览: 26
在WPF中,可以通过设置ListBox的ItemContainerStyle的Trigger来实现选中条目变颜色的效果。具体实现方式如下:
1. 在ListBox的ItemContainerStyle中添加一个Trigger,当IsSelected为True时,设置Background颜色。
```
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Yellow" />
</Trigger>
</Style.Triggers>
</Style>
</ListBox.ItemContainerStyle>
```
2. 在ListBox的SelectionMode属性中设置为Single或Multiple,表示单选或多选。
```
<ListBox SelectionMode="Single">
<ListBoxItem>Item 1</ListBoxItem>
<ListBoxItem>Item 2</ListBoxItem>
<ListBoxItem>Item 3</ListBoxItem>
</ListBox>
```
这样,当你选择ListBox中的某个条目时,该条目的背景颜色就会变成黄色。