Metro app - ListView - how to alternate background colour of ListViewItems

前端 未结 4 834
没有蜡笔的小新
没有蜡笔的小新 2020-12-19 04:26

In my Metro style app for Windows 8, I\'m binding a Listview to an ObservableCollection and I would like the background color of each ListViewItem to alternate (white, gray

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-19 04:59

    You can use a converter - grab a row index from an item and convert it to a brush. Also - if ItemTemplate does not give you enough control - use ItemContainerStyle to modify the brush at the ListViewItem template level.

    Another option might be to specify an ItemTemplateSelector that gives you a different template with a different brush depending on an item. You would still need to generate row indices though or somehow enable the selector to determine if the item is at an even or odd position.

提交回复
热议问题