【发布时间】:2011-03-24 01:26:34
【问题描述】:
如何使用 .net 2.0 在 ListView 中设置交替行的背景颜色(例如:第 1、第 3、第 5、第 7...)。
【问题讨论】:
标签: listview c#-2.0 rows background-color
如何使用 .net 2.0 在 ListView 中设置交替行的背景颜色(例如:第 1、第 3、第 5、第 7...)。
【问题讨论】:
标签: listview c#-2.0 rows background-color
RTMhere.
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;
}
}
【讨论】:
if 语句。