我想更改ListBoxItem的背景颜色
搜索后我决定使用它
<ListBox>
<ListBox.Resources>
<!-- Background of selected item when focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Blue" />
<!-- Background of selected item when not focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="Blue" />
</ListBox.Resources>
<TextBlock>fdfsdf1</TextBlock>
<TextBlock>fdfsdf3</TextBlock>
<TextBlock>fdfsdf5</TextBlock>
<TextBlock>fdfsdf3</TextBlock>
<TextBlock>fdfsdf4</TextBlock>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
当一个listboxitem被聚焦时,背景是预期的蓝色,但是当所选的listboxitem失去焦点时,背景变为灰色.当失去焦点时,如何使背景保持蓝色?
sa_*_*213 14
如果你的意思是它的选择但不活跃的尝试 InactiveSelectionHighlightBrushKey
<ListBox.Resources>
<!-- Background of selected item when focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="Blue" />
<!-- Background of selected item when not focussed -->
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}"
Color="Blue" />
</ListBox.Resources>
Run Code Online (Sandbox Code Playgroud)
试试这个
<ListBox>
<ListBox.Resources>
<Style TargetType="ListBoxItem">
<Setter Property="Background" Value="Blue" />
</Style>
</ListBox.Resources>
<TextBlock>fdfsdf1</TextBlock>
<TextBlock>fdfsdf3</TextBlock>
<TextBlock>fdfsdf5</TextBlock>
<TextBlock>fdfsdf3</TextBlock>
<TextBlock>fdfsdf4</TextBlock>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19232 次 |
| 最近记录: |