Introduction
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.
- public class Person
- {
- public string Name { get; set; }
- public int Age { get; set; }
- public string Country { get; set; }
- }
- ObservableCollection<Person> myList;
- public Window1()
- {
- InitializeComponent();
- myList = new ObservableCollection<Person>()
- {
- new Person{ Name="Name 1", Age=24, Country="India"},
- new Person{ Name="Name 2", Age=24, Country="India"},
- new Person{ Name="Name 3", Age=24, Country="India"},
- new Person{ Name="Name 4", Age=24, Country="India"},
- new Person{ Name="Name 5", Age=24, Country="India"},
- new Person{ Name="Name 6", Age=24, Country="India"},
- new Person{ Name="Name 7", Age=24, Country="India"},
- new Person{ Name="Name 8", Age=24, Country="India"},
- new Person{ Name="Name 9", Age=24, Country="India"},
- new Person{ Name="Name 10", Age=24, Country="India"},
- new Person{ Name="Name 11", Age=24, Country="India"},
- new Person{ Name="Name 12", Age=24, Country="India"},
- new Person{ Name="Name 13", Age=24, Country="India"},
- new Person{ Name="Name 14", Age=24, Country="India"},
- new Person{ Name="Name 15", Age=24, Country="India"},
- new Person{ Name="Name 16", Age=24, Country="India"},
- new Person{ Name="Name 17", Age=24, Country="India"},
- new Person{ Name="Name 18", Age=24, Country="India"},
- new Person{ Name="Name 19", Age=24, Country="India"},
- new Person{ Name="Name 20", Age=24, Country="India"},
- new Person{ Name="Name 21", Age=24, Country="India"},
- new Person{ Name="Name 22", Age=24, Country="India"},
- };
- lbPersonList.ItemsSource = myList;
- }



Nitesh KhanchandaniPosted Jun 28, 2011, 11:59 AM
Have just started with WPF. This was the easiest way of doing it :) any articles for drawing borders around the GridVIew Cells inside a ListView in WPF??
Suresh KumarPosted Jan 3, 2010, 3:26 PM
thanks good articles............