2010-08-02 86 views

回答

2

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; 
     } 
    } 
+0

哪個名稱空間(.net 2.0)包含IValueConverter接口? – Samir 2010-08-02 06:27:16

+0

你可以圍繞該接口進行編碼,如果必須的話,你可以用for循環填充列表。這段代碼的重要部分是用於你的目的的是使用mod運算符的'if'語句。 – ubiquibacon 2010-08-02 06:34:10