Thread ID:

Created:

Updated:

Platform:

Replies:

When I put a background color on a data template for a listview, the highlight color when I select the item on the list does not appear on the cell anymore. I need each item on the list to have a white background, but also need it to be highlighted when selected as normal.

I tried setting the background color of the list view to white, but that caused the whole list to turn white, I only need the items to have a white background.

By default, when background color is defined for DataTemplate and performing selection, the background color is not updated for the selected item and this is the actual behavior.. However, the reported requirement “Item background color should be highlighted when selection is performed and background color is defined for DataTemplate” can be achieved by a workaround with customizing the data model and by using custom convertor. In the data model, define a IsSelected property which indicates whether the item is selected or not and when selection is performed, need to update IsSelected property in the data model to trigger the custom convertor class, which you have bind it to Grid in the ItemTemplate property. You can achieve this by using the SelectionChanged event as like below code snippet,

For your reference, we have attached the working sample which change the background color of the Grid based on the IsSelected property from the Custom Convertor class(returns the desired color based on the IsSelected value) and by default the background color of item will be White and after selection is performed the background color is changed to Blue. You can download the sample from the below link.

this helped me to understand my problem. Thanks for the example. Any chance we can some day change the default behavior so that selecting a item does replace a defined background color? No more custom code needed that way

Currently we do not have support for “Customizing the SelectedItem UI”. We have already considered this as feature request and added it to our feature request list. The reported feature is a tentative feature and it will be available in any of our upcoming releases. We will let you know once the feature has been implemented.