wpf listbox selecteditem background colour change without changing system brush

心已入冬 提交于 2021-01-29 20:21:39

问题


I have a Listbox control that I want to remove selection highlighting from. I know the initial instinct will be to suggest overriding the system highlight brush colour but unfortunately that seems to do so for all controls, and I have an embedded combobox within the listboxitem template that I do NOT want the selected item to be transparent for.

Is there a way to change the selected item highlight colour without changing the system highlight brush?


回答1:


Apply the style directly to the ListBox

<ListBox  ... >
   <ListBox.ItemContainerStyle>
       <Style TargetType="ListBoxItem">
          <Style.Resources>
             <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Yellow"/>
          </Style.Resources>
       </Style>                
   </ListBox.ItemContainerStyle>


来源:https://stackoverflow.com/questions/17994753/wpf-listbox-selecteditem-background-colour-change-without-changing-system-brush

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!