For setting the background color of Listview rows in an alternate fashion (odd rows and even rows) at first create a style element :
<Style x:Key="alternatingStyle" TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="LightSkyBlue"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="LightGray"></Setter>
</Trigger>
<Trigger Property="IsSelected" Value="True">
<Setter Property="Background" Value="Orange"/>
</Trigger>
</Style.Triggers>
</Style>
Now write this XAML code for ListView
<ListView BorderBrush="#FFA8CC7B" Height="133" HorizontalAlignment="Left"
Margin="88,382,0,0"Name="lvInvDetails" VerticalAlignment="Top" Width="596"
ItemContainerStyle="{StaticResource alternatingStyle}" AlternationCount="2">
<ListView.View>
<GridView>
<GridViewColumn DisplayMemberBinding="{Binding Path=InvoiceDetailsItemId}"
Header="Item Id" Width="90" />
<GridViewColumn DisplayMemberBinding="{Binding Path=InvoiceDetailsItemName}"
Header="Item Name" Width="120" />
</GridView>
</ListView.View>
</ListView>
enjoy...
Comments
Post a Comment