zoukankan      html  css  js  c++  java
  • <转>Change the Background of a selected ListBox Item

    If you select an item in a listbox it gets the default selection color (usually blue) as background. Even if you specify a custom data template. The reason is that the blue background (or gray if the control is not focussed) is drawn outside of the data template. So you have no chance to override it from within the data template.

    The color used to draw the blue and gray background are system colors. So the easiest way to get rid of these backgrounds is to locally override the highlight and control brushes of the system colors.

    The best way to do this is to create a style for the listbox. Place the style in the resources of a parent element. For e.g. Window.Resources

    The following XAML snippet shows how to apply the style to the listbox.

    1 <Style x:Key="myListboxStyle">
    2 <Style.Resources>
    3 <!-- Background of selected item when focussed -->
    4 <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />
    5 <!-- Background of selected item when not focussed -->
    6 <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Green" />
    7 </Style.Resources>
    8  </Style>
  • 相关阅读:
    Java 编程规范
    Java常考面试题
    SQL 实战
    快速排序
    剑指Offer(51-67)
    剑指Offer(41-50)
    移动端图片编辑器
    css隐藏和显示table的第一列
    sweetAlert1 设置弹窗宽度,及使用自定义样式
    js获取yyyy-mm-dd hh:mm:ss格式的当前系统时间
  • 原文地址:https://www.cnblogs.com/midcn/p/1993974.html
Copyright © 2011-2022 走看看