namedajipai
namedajipai
2016-05-09 15:10
采纳率: 90.6%
浏览 1.4k
已采纳

windows系统的listview实现隔行变色的功能?

windows系统的listview实现隔行变色的功能?怎么给偶数行增加一个浅色底纹,显得更加醒目?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • caozhy
    已采纳
    点赞 评论
  • oyljerry
    oyljerry 2016-05-10 01:32
    点赞 评论
  • u014339882
    TOP-尼古丁味道 2016-05-11 11:54

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Windows.Data;
    using System.Windows.Controls;
    using System.Windows.Media;

    public class ListViewBackgroundConverter :IValueConverter
    {
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
    ListViewItem item = (ListViewItem)value;
    ListView listView =
    ItemsControl.ItemsControlFromItemContainer(item) as ListView;

            int index = listView.ItemContainerGenerator.IndexFromContainer(item);
    
            if (index % 2 == 0)
            {
                return Brushes.White;
            }
            else
            {
                return Brushes.WhiteSmoke;
            }
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotSupportedException();
        }
    }
    
    
    
    点赞 评论

相关推荐