mscommunity.net

Interactive mscommunity.net online activities
Signed in as anonymous | Edit Profile | Sign out | Help
in Search

Weblog :: Boris Ševo

Sporadic posts about my interests, e.g. software development (mostly .NET), technology in general and some occasional rant.

WPF trick #2 - Alternate background colors for ListView rows

Prior the .NET Framework 3.5 SP1 was released, if you want to set alternate background colors for ListView rows you needed to write some kind Converter which returnes some kind of Brush. IF you have SP1 installed accomplishing the same functionality is rather trivial job. Here are the code snippets:

(defining the style)

    <Style x:Key="CustomListViewItemStyle" TargetType="{x:Type ListViewItem}">
<Style.Triggers>
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
<Setter Property="Background" Value="#2C2C2C"></Setter>
</Trigger>
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
<Setter Property="Background" Value="#262626"></Setter>
</Trigger>
</Style.Triggers>
</Style>

(using the defined style)

    <ListView ItemContainerStyle="{DynamicResource CustomListViewItemStyle}"
AlternationCount="2">
...
</ListView>
Published lis 21 2008, 04:22 by boris.sevo
Filed under:

Comments

 

anonymous said:

thanks a lot! your guide helps me save a lot of time for finding this.

kolovoz 29, 2009 6:23
 

anonymous said:

Fantastic. This saved my day!

prosinac 29, 2009 10:47
 

anonymous said:

Thank you very much.

Worked great!

Kind regards

veljača 11, 2010 3:14
 

anonymous said:

Thanks very much for this, was very helpful!

srpanj 19, 2010 11:45
 

anonymous said:

Worked really well. Quick and simple! Thanks.

kolovoz 19, 2010 5:35

Leave a Comment

(required) 
(optional)
(required) 
Submit
Powered by Community Server (Commercial Edition), by Telligent Systems