改变ListBoxItem选中的颜色

简介: 原文:改变ListBoxItem选中的颜色改变ListBoxItem主要是改变的style   下面直接看代码吧!!! 1 2 3 4 5 ...
原文: 改变ListBoxItem选中的颜色

改变ListBoxItem主要是改变的style

 

下面直接看代码吧!!!

 1   <Style TargetType="{x:Type ListBoxItem}">
 2              <Setter Property="SnapsToDevicePixels" Value="true"/>
 3              <Setter Property="OverridesDefaultStyle" Value="true"/>
 4              <Setter Property="Template">
 5                  <Setter.Value>
 6                      <ControlTemplate TargetType="{x:Type ListBoxItem}">
 7  
 8                          <Grid SnapsToDevicePixels="true">
 9                              <Border x:Name="Border" Background="Aqua"/>
10                              <ContentPresenter />
11                          </Grid>
12                          <ControlTemplate.Triggers>
13                              <Trigger Property="IsSelected" Value="true">
14                                  <Setter Property="Background" TargetName="Border" Value="Red"/>
15                              </Trigger>
16                          </ControlTemplate.Triggers>
17                      </ControlTemplate>
18                  </Setter.Value>
19              </Setter>
20          </Style>

 

在第一行代码要注意的是

<Style TargetType="{x:Type ListBoxItem}">这里没有使用x:key属性

这样模块下所有的ListBoxItem

总结:当ListBoxItem中指定了style时,就不会使用到以上定义的样式。

根据上文指定了ListBoxItem 自动填充ListBox
 <ListBox.ItemContainerStyle>
3     <Style TargetType="ListBoxItem">
4       <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
5     </Style>
6   </ListBox.ItemContainerStyle>

 


可以把上面的样式写在这里,但是这两个样式不能同使用。

 

目录
相关文章
|
20天前
|
前端开发
复选框样式修改(复选框变为圆形)
复选框样式修改(复选框变为圆形)
|
8月前
|
小程序
小程序滚动时使标题背景颜色改变
小程序滚动时使标题背景颜色改变
63 0
|
12天前
echars 设置文字倾斜 图表根据鼠标滑轮自动改变x轴数据
echars 设置文字倾斜 图表根据鼠标滑轮自动改变x轴数据
12 1
|
6月前
|
JavaScript
checkbox选中和取消,控制dom元素颜色变化
checkbox选中和取消,控制dom元素颜色变化
26 0
|
6月前
|
前端开发
鼠标点击<input>输入框后边框发生颜色变化
鼠标点击<input>输入框后边框发生颜色变化
41 0
|
C++
VS C++改变窗体背景色
VS C++改变窗体背景色
123 0
输出框的背景和字体颜色改变
输出框的背景和字体颜色改变
77 0
输出框的背景和字体颜色改变
|
C#
C#-改变表格行颜色
C#改变表格行颜色
237 0
布局之悬浮显示更多文本并增加箭头指示效果
布局之悬浮显示更多文本并增加箭头指示效果
93 0
布局之悬浮显示更多文本并增加箭头指示效果
改变DBGRID的选中行的颜色
默认DBGRID选中行的颜色为深蓝色,可以在程序中改变 在DBGRID的OnDrawColumnCell中写入 if (State=[gdSelectd..gdFocused,gdCurrent]) then begin    Grid.
850 0