How would I set the background color for for alternating rows (say: 1st, 3rd, 5th, 7th...) in a ListView using .net 2.0.
+2
A:
RTM here.
public sealed class BackgroundConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter,
CultureInfo culture)
{
ListViewItem item = (ListViewItem)value;
ListView listView =
ItemsControl.ItemsControlFromItemContainer(item) as ListView;
// Get the index of a ListViewItem
int index =
listView.ItemContainerGenerator.IndexFromContainer(item);
if (index % 2 == 0)
{
return Brushes.LightBlue;
}
else
{
return Brushes.Beige;
}
}
typoknig
2010-08-02 06:19:31
Which name space (.net 2.0) contains IValueConverter interface?
Samir
2010-08-02 06:27:16
You can code around that interface, you could populate the list with a for loop if you had to. The important part of this code for your purposes is the `if` statement with the mod operator.
typoknig
2010-08-02 06:34:10