ListView desperately needs a SelectedItemBackgroundColor property

LouisTaljaardLouisTaljaard ZAMember ✭✭
edited November 1 in Xamarin.Forms Evolution

It's a very basic thing, nobody wants an ugly grey (or blue) 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 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 the selected item's background color to something that matches your app's color scheme. And 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 approach 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 mentioned in paragraph above):

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 (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.

0
0 votes

Open · Last Updated

Posts

  • CatoLommerudCatoLommerud USMember

    I wholeheartedly support this request

  • SharpDoctorSharpDoctor USMember

    We need this BASIC functionality it's just a simple color, nothing fancy(gradient, images, ...)

  • LordDzLordDz SEMember
    edited November 21

    I totally agree. Xamarin needs more of the simple things to simply work rather than having to lookup how to create customrenderers for a.. color.

Sign In or Register to comment.