1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
public class ListViewItemStyleSelector : StyleSelector
{
private int i = 0;
public override Style SelectStyle(object item, DependencyObject container)
{
// makes sure the first item always gets the first style, even when restyling
ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(container);
if (item == ic.Items[0])
{
i = 0;
}
string styleKey;
if (i % 2 == 0)
{
styleKey = ListViewItemStyle1″;
}
else
{
styleKey = ListViewItemStyle2″;
}
i++;
return (Style)(ic.FindResource(styleKey));
}
} |
Partager