实现wpf listview listbox 隔行变色的简单方法

2017-09-19 20:39:14来源:CSDN作者:qq_37429590人点击

分享
第七城市
<Window x:Class="WpfApplication3.MainWindow"        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"        xmlns:local="clr-namespace:WpfApplication3"        mc:Ignorable="d"        Title="MainWindow" Height="350" Width="525">    <Window.Resources>        <Style TargetType="{x:Type ListBoxItem}">            <Setter Property="Background" Value="Red"/>            <Style.Triggers>                <Trigger Property="ListBox.AlternationIndex" Value="1">                    <Setter Property="Background" Value="OrangeRed"/>                </Trigger>                <Trigger Property="ListBox.AlternationIndex" Value="2">                    <Setter Property="Background" Value="Orange"/>                </Trigger>                <Trigger Property="ListBox.AlternationIndex" Value="3">                    <Setter Property="Background" Value="Green"/>                </Trigger>                <Trigger Property="ListBox.AlternationIndex" Value="4">                    <Setter Property="Background" Value="LightGreen"/>                </Trigger>                <Trigger Property="ListBox.AlternationIndex" Value="5">                    <Setter Property="Background" Value="Blue"/>                </Trigger>                <Trigger Property="ListBox.AlternationIndex" Value="6">                    <Setter Property="Background" Value="LightBlue"/>                </Trigger>            </Style.Triggers>        </Style>        <Style  TargetType="{x:Type ListBox}">            <Setter Property="AlternationCount" Value="7"/>        </Style>    </Window.Resources>    <Grid>        <ListBox x:Name="ListBox">            <ListBoxItem>1</ListBoxItem>            <ListBoxItem>2</ListBoxItem>            <ListBoxItem>3</ListBoxItem>            <ListBoxItem>4</ListBoxItem>            <ListBoxItem>5</ListBoxItem>            <ListBoxItem>6</ListBoxItem>            <ListBoxItem>7</ListBoxItem>            <ListBoxItem>8</ListBoxItem>            <ListBoxItem>9</ListBoxItem>        </ListBox>    </Grid></Window>

这里写图片描述

第七城市

最新文章

123

最新摄影

闪念基因

微信扫一扫

第七城市微信公众平台