wpf ListBox 选中项背景颜色的修改
2014-08-15 15:38
751 查看
关键代码: <Style TargetType="ListBoxItem">
<Style.Resources>
<!--ListBox 选中一项时背景颜色-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<!--选中项失去焦点后的颜色-->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</Style.Resources>
</Style>
使用方法如下:
<StackPanel Grid.Row="1" Orientation="Vertical">
<StackPanel.Resources>
<Style TargetType="ListBoxItem">
<Style.Resources>
<!--ListBox 选中一项时背景颜色-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<!--选中项失去焦点后的颜色-->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</Style.Resources>
</Style>
</StackPanel.Resources>
<ListBox Margin="0,20,0,0" MaxWidth="800" Focusable="False" Background="Transparent" BorderBrush="Transparent" Name="mainListBox" MaxHeight="470"
VerticalAlignment="Top"
MinHeight="350" >
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel
Orientation="Horizontal" >
<Label MinWidth="120" VerticalAlignment="Center" FontSize="24" Foreground="Black" Content="{Binding Department}"></Label>
<ListBox MaxWidth="590" Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Hidden"
ScrollViewer.HorizontalScrollBarVisibility="Auto" BorderBrush="Transparent" Margin="67,0,0,0" ItemsSource="{Binding imageList}">
<ListBox.ItemTemplate>
<DataTemplate >
<Grid
>
<u:PrintImageCtrl PrintState="{Binding printStaute}" Margin="15,0,0,0" >
</u:PrintImageCtrl>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel HorizontalAlignment="Center" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label Content="正在打印........." Foreground="#787878" FontSize="38" FontWeight="Bold" HorizontalAlignment="Center"></Label>
</StackPanel>
我的这段代码的作用如下
使用那段黄色标记的代码后 单机ListBox的任何一项就不会出现丑陋的蓝色背景了。
<Style.Resources>
<!--ListBox 选中一项时背景颜色-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<!--选中项失去焦点后的颜色-->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</Style.Resources>
</Style>
使用方法如下:
<StackPanel Grid.Row="1" Orientation="Vertical">
<StackPanel.Resources>
<Style TargetType="ListBoxItem">
<Style.Resources>
<!--ListBox 选中一项时背景颜色-->
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" />
<!--选中项失去焦点后的颜色-->
<SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}" Color="Transparent" />
</Style.Resources>
</Style>
</StackPanel.Resources>
<ListBox Margin="0,20,0,0" MaxWidth="800" Focusable="False" Background="Transparent" BorderBrush="Transparent" Name="mainListBox" MaxHeight="470"
VerticalAlignment="Top"
MinHeight="350" >
<ListBox.ItemTemplate>
<DataTemplate >
<StackPanel
Orientation="Horizontal" >
<Label MinWidth="120" VerticalAlignment="Center" FontSize="24" Foreground="Black" Content="{Binding Department}"></Label>
<ListBox MaxWidth="590" Background="Transparent" ScrollViewer.VerticalScrollBarVisibility="Hidden"
ScrollViewer.HorizontalScrollBarVisibility="Auto" BorderBrush="Transparent" Margin="67,0,0,0" ItemsSource="{Binding imageList}">
<ListBox.ItemTemplate>
<DataTemplate >
<Grid
>
<u:PrintImageCtrl PrintState="{Binding printStaute}" Margin="15,0,0,0" >
</u:PrintImageCtrl>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel HorizontalAlignment="Center" Orientation="Horizontal" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Label Content="正在打印........." Foreground="#787878" FontSize="38" FontWeight="Bold" HorizontalAlignment="Center"></Label>
</StackPanel>
我的这段代码的作用如下
使用那段黄色标记的代码后 单机ListBox的任何一项就不会出现丑陋的蓝色背景了。
相关文章推荐
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- 如何修改UIPickerView选中行背景颜色
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- wpf 设置treeView节点选中后的的文字颜色、节点的背景色以及节点失去焦点后的背景颜色
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- WPF中ListView如何改变选中条背景颜色
- css 修改页面选中时背景颜色
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- 设置 ListBox 选中项的背景颜色
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- PHPStorm怎么修改选中的背景颜色呢?
- 关于PHPstorm的代码选中背景颜色的修改
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- PHPStorm怎么修改选中的背景颜色呢?
- vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- WPF中ListView如何改变选中条背景颜色
- LISTBOX控件:vc修改列表框LISTBOX的背景颜色及字体颜色及其使用方法
- delphi TreeView修改选中的节点的颜色和背景