Alternate Row Color In ListBox In WPF
In this article we will see how we can make the Alternate Rows of the ListBox Colorful in WPF.
Creating WPF Project
Fire up Visual Studio 2008 and create a new WPF Project. Name it as ListBoxSampleWPF.
Now we will add a ListBox to the Application and it will look as following:
Now let’s add some sample data to the ListBox.
myList = new
lbPersonList.ItemsSource = myList;
Now Bind the Property “Name” to the ListBox, so that we can see the Names.
<ListBox x:Name=”lbPersonList” Margin=”19,17,162,25″>
If you see from the above wecannot differentiate with each row, I mean to say the Row Background color is all same white.
Now we would add a style to the ListBoxItem.
<ListBox x:Name=”lbPersonList” Margin=”19,17,162,25″
Now run the application.
Yes, we got alternate row colors.
We can have value more than 2 as AlternationCount and add that many colors and you will see the Repeatation of colors after the AlternationCount.
Hope this article helps.