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

懵懂的女人 提交于 2019-11-29 10:19:44

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.

I believe the code sample here is useful https://msdn.microsoft.com/en-us/library/ms750769(v=vs.85).aspx

Never tried to do styling like this but what if:

you bind a background color to some property and that property will be set via IValueConverter according to maybe index of current item in listview.

If I make any sense.

Edit:

Funny thing, while i was writing my answer, Filip Skakun came with exactly same idea.

I search online and found a technique that included adding an index property to the model in question and then adding a converter to the DataTemplate. This wasn’t ideal because it only changed the contents of the list item, so depending on padding and content alignment you’d see gaps around the row background. I also didn’t like the code smell of modifying my data model objects with UI code.

Try this it will help, http://www.bendewey.com/index.php/523/alternating-row-color-in-windows-store-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!