[英]How is it possible to change datagrid cell background color when is selected and focused?
[英]Change background color of ListBoxItem when it is not focused
当选定的ListBoxItem未聚焦且包含的窗口未处于活动状态时,我尝试更改它的Backgroundcolor。 该窗口具有ShowActivated = false.
但是它仍然是灰色的。
这是我的代码:
<ListBox x:Name="oList" >
<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}">
<EventSetter Event="MouseDoubleClick"
Handler="listBoxItem_DoubleClick" />
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
Color="LightGreen" />
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
Color="LightBlue" />
</Style.Resources>
</Style>
</ListBox.ItemContainerStyle>
<ListBoxItem Content="Coffie"></ListBoxItem>
<ListBoxItem Content="Tea"></ListBoxItem>
<ListBoxItem Content="Orange Juice"></ListBoxItem>
<ListBoxItem Content="Milk"></ListBoxItem>
<ListBoxItem Content="Iced Tea"></ListBoxItem>
<ListBoxItem Content="Mango Shake"></ListBoxItem>
</ListBox>
我希望有人可以帮助我,我做错了什么。
尝试将其添加到您的Style.Resources
(根据您的喜好更改颜色):
<SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="LightBlue"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.