Bug 26544 - Cell's background color is set to TRANSPARENT in iOS custom cell renderer but it shows up WHITE
Summary: Cell's background color is set to TRANSPARENT in iOS custom cell renderer but...
Status: RESOLVED ANSWERED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 1.3.2
Hardware: PC Mac OS
: Highest normal
Target Milestone: ---
Assignee: Rui Marinho
URL:
Depends on:
Blocks:
 
Reported: 2015-01-29 11:01 UTC by Borislav Parvanov
Modified: 2015-05-29 15:07 UTC (History)
7 users (show)

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


Attachments
Repro for ghosting issue. (3.33 MB, application/x-zip-compressed)
2015-01-29 22:09 UTC, Ian Geoghegan
Details


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:
Status:
RESOLVED ANSWERED

Description Borislav Parvanov 2015-01-29 11:01:41 UTC
NOTE: This worked correctly in Xamarin Forms versions <= 1.2.3

In the example below listview has background color set to CYAN.
Since listview cells' background is set ot UIColor.Clear in their custom renderer, they are supposed to have the same background as the listview (i.e.CYAN)
Instead, in XF >= 1.3.0 we can see the background is WHITE.


// AppDelegate.cs

using System;
using System.Collections.Generic;
using System.Linq;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly:ExportRenderer(typeof(TestXF.CustomCell), typeof(TestXF.iOS.CustomCellRenderer))]
[assembly:ExportRenderer(typeof(TestXF.CustomListView), typeof(TestXF.iOS.CustomListViewRenderer))]
namespace TestXF.iOS
{
	public class CustomCellRenderer : ViewCellRenderer
	{
		#if true // ver <= 1.2.3
		public override UITableViewCell GetCell (Cell item, UITableView tv)
		{
			var cell = base.GetCell (item, tv);
		#else // ver > 1.2.3
		public override UITableViewCell GetCell (Cell item, UITableViewCell reusableCell, UITableView tv)
		{
		var cell = base.GetCell (item, reusableCell, tv);
		#endif
			cell.SelectedBackgroundView = new UIView { BackgroundColor = UIColor.Red };

			// if XF is <  1.3.0 the following line works (i.e. cell's background color becomes transparent)
			// if XF is == 1.3.0 background color is always white.. 
			// if XF is >= 1.3.1 initially background color is white (wrong behaviour), and when you tap the cell it 
			// becomes transparent (as it is supposed to be)
			cell.BackgroundColor = UIColor.Clear; 
			return cell;
		}
	}

	public class CustomListViewRenderer : ListViewRenderer 
	{
		protected override void OnElementChanged (ElementChangedEventArgs<ListView> e)
		{
			base.OnElementChanged (e);

			if (e.OldElement != null || this.Element == null)
				return;

			var tableView = Control;

			tableView.BackgroundView = new UIView { BackgroundColor = UIColor.Cyan };
			tableView.SeparatorStyle = UITableViewCellSeparatorStyle.None;
		}
	}

	[Register ("AppDelegate")]
	public partial class AppDelegate : UIApplicationDelegate//global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
	{
		UIWindow window;

		public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
		{
			Xamarin.Forms.Forms.Init();

			window = new UIWindow(UIScreen.MainScreen.Bounds);

			window.RootViewController = App.GetMainPage().CreateViewController();

			window.MakeKeyAndVisible();

			return true;
		}
	}
}



// TestXF.cs

using System;
using Xamarin.Forms;

namespace TestXF
{
	public class CustomCell : ViewCell
	{
		public CustomCell ()
		{
			var label = new Label ();
			label.SetBinding (Label.TextProperty, ".");
			View = label;
		}
	}

	public class CustomListView : ListView
	{
	}

	public class App
	{
		public static Page GetMainPage ()
		{
			return new ContentPage {
				Content = new CustomListView {
					ItemTemplate = new DataTemplate (typeof(CustomCell)),
					ItemsSource = new string[] { "Item 1", "Item 2", "Item 3" }
				}
			};
		}
	}
}
Comment 1 Ian Geoghegan 2015-01-29 22:07:15 UTC
I also have encountered this issue and am attaching a repro.
Comment 2 Ian Geoghegan 2015-01-29 22:09:19 UTC
Created attachment 9574 [details]
Repro for ghosting issue.
Comment 3 Abhishek 2015-02-02 10:26:05 UTC
I have tried this issue and able to reproduce the reported behavior at my end.

Step to Reproduce:
1. Download the attach sample given above.
2. Run the application on the simulator.
3. "Swipe for the side nav please" it show the two list view "Click me" and "No,Click me".
4. Click simultaneously on "Click me" and "No,Click me" it will show white color.  

Screencast: http://www.screencast.com/t/w562iRuxzTL3
Device Log: https://gist.github.com/AkhileshKumar01/a8dc23c717b45355f75d


Build Info:
Xamarin.Forms: 1.3.1.6296
Xamarin.Forms: 1.3.2.6313-pre3.

=== Xamarin Studio ===

Version 5.7.1 (build 14)
Installation UUID: 93e693b0-b53d-40f4-b29c-b61ff5cbe892
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1 (6604)
Build 6A1052d

=== Xamarin.Mac ===

Version: 1.12.0.4 (Business Edition)

=== Xamarin.Android ===

Version: 5.0.0.17 (Business Edition)
Android SDK: /Users/xamarin23/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin.iOS ===

Version: 8.6.1.20 (Business Edition)
Hash: 3b3ef43
Branch: 
Build date: 2015-01-24 09:42:21-0500

=== Build Information ===

Release ID: 507010014
Git revision: a4dd61ad7f8b3695be4b17bcb5c3ae6b81438cf7
Build date: 2015-01-19 15:21:09-05
Xamarin addins: 081208fe3bbf40e24a562867c6c7fba20a9b94b6

=== Operating System ===

Mac OS X 10.10.0
Darwin 800BC.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 4 Seth Rosetter 2015-02-09 17:09:11 UTC
I have checked this issue and we do not support the setting individual cell background colors in custom renderers. This may and probably will have unexpected results. However, you are able to set the listView.BackgroundColor (in Forms code) and the background color of the cell will take this value. This even works with Color.Transparent or a Forms Color with alpha if you want to achieve transparency. I have tried setting the BackgroundColor of the forms ListView in the attached repro project from Ian and it demonstrates the behavior you were trying to achieve with the cell.BackgroundView assignment in the custom renderer.

I am closing this issue as resolved. 

Thanks!
Comment 5 Ian Geoghegan 2015-02-16 12:58:33 UTC
Seth,

Prior to the December releases of Xamarin Forms I was able to author a custom ImageCell renderer that allowed the consistent manipulation of the UITableView and UITableViewCell on the GetCell method. This seemed consistent with the intent and design of the renderer architecture. Was this functionality intentionally removed? If so, why? If not, when can we expect it to be repaired?

Setting the background color on the ListView is only a partial solution as there doesn't seem to be a way to set the background color of a selected item. Please advise; thank you for your time.
Comment 6 bryan costanich 2015-02-17 13:37:31 UTC
Jason, I think that Ian makes a good point here. Is there a limitation that we're hitting that makes this difficult to fix?
Comment 7 Rui Marinho 2015-05-29 15:07:57 UTC
Hi, please update to 1.4.2 and set your ListView to be transparent, like so:

listView.BackgroundColor = Color.Transparent;

Thanks