您的位置:首页 > 其它

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的任何一项就不会出现丑陋的蓝色背景了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  wpf ListBox ListBoxI