Bug 60483 - ListView desperately needs a SelectedItemBackgroundColor property
Summary: ListView desperately needs a SelectedItemBackgroundColor property
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.4.0
Hardware: All All
: Normal enhancement
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2017-11-01 23:07 UTC by Louis Taljaard
Modified: 2017-11-01 23:11 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Louis Taljaard 2017-11-01 23:07:27 UTC
It's a very basic thing, nobody wants' an ugly gray bar to appear as the background when you select an item in a ListView. It looks terrible from a UI point of view. Everybody has been implementing their own workarounds for this (custom renderers etc) but it is getting out of hand.

The ViewCellRenderer custom renderer approach works fine with a ListView with the default caching strategy ListViewCachingStrategy.RetainElement but it does NOT work if you set it to ListViewCachingStrategy.RecycleElement or ListViewCachingStrategy.RecycleElementAndDataTemplate .

If you need a different caching strategy you have to go one step further and create a custom ListViewRenderer renderer for your ListView and then assign your own UITableViewDelegate based delegate, and from there you need to override the WillDisplay method in order to eventually be able to set eh selected item's background color to something that matches your app's color scheme! And even after all this you'll find there are problems with the fact that you're replacing the "default delegate". (note: conversely and ironically this ListViewRenderer seems to work ok with a ListView that has a non-default caching strategy set but it does NOT work with the default caching strategy - in the latter case it doesn't pick up the ItemSelected event anymore!). : The problem with overwriting the default delegate is described here: https://forums.xamarin.com/discussion/42863/setting-delegate-of-control-in-custom-renderer-results-in-lost-functionality

The problem and various workarounds that people have been trying is summarised here (but still there are some problems as per previous paragraph above):
* https://forums.xamarin.com/discussion/20798/listview-selected-item-background-color
* https://stackoverflow.com/posts/47054718

In short this is madness that each developer must go through all this pain for such a simple thing!

To solve all this a simple SelectedItemBackgroundColor property should be added to the ListView class. It won't be difficult to add the required code into the ListView class itself (just some code in the custom renderers will do the trick). Then we won't have to worry about all these custom renders or about how to handle the "overwritten" default delegate.
Comment 1 Paul DiPietro [MSFT] 2017-11-01 23:11:25 UTC
Please take all API proposals to the X.F. Evolution forum. Thanks!