Bug 38432 - ViewCell in listview has non-zero layoutmargins
Summary: ViewCell in listview has non-zero layoutmargins
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: iOS ()
Version: 2.0.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-02-04 08:35 UTC by Kenneth
Modified: 2016-12-20 23:03 UTC (History)
1 user (show)

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


Attachments
Simulator screenshot showing the problem (49.00 KB, image/png)
2016-02-04 08:35 UTC, Kenneth
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 FIXED

Description Kenneth 2016-02-04 08:35:56 UTC
Created attachment 14886 [details]
Simulator screenshot showing the problem

The ViewCell element has no padding properties in Xamarin.Forms but has a LayoutMargin on UITableViewCell.
I think the intention was to cancel out this, such that the Forms side can use padding to achieve the same effect.

But since the LayoutMargins are not cleared, it comes with a default 8,8,8,8 margin on iOS.
For some reason, only the left and right margins are set, but the give a 16 px margin on the right.
I assume this is because Forms is attempting to ignore the LayoutMargins but fails somewhere.

I have attached a screenshot where the contents of the ViewCell are "aqua" and the ListView background is "blue", so you can see the spacing issue.

The Xaml that produces this is:
```
<StackLayout VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
	<SearchBar HorizontalOptions="FillAndExpand" VerticalOptions="Start" />
	<ListView BackgroundColor="Blue" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
		
		<ListView.ItemTemplate>
			<DataTemplate>
				<ViewCell>
					<StackLayout Orientation="Horizontal" MinimumHeightRequest="48" BackgroundColor="Aqua" HorizontalOptions="FillAndExpand">

						<Image WidthRequest="48" HeightRequest="48" Source="{Binding FastBlobImage}" HorizontalOptions="Start" />

						<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="Center" Padding="0, 0, 0, 0" Spacing="2">
							<Label Text="{Binding Name}" FontAttributes="Bold" FontSize="14" VerticalOptions="Center" />
							<Label Text="{Binding Brewery}" FontSize="14" VerticalOptions="Center" />
						</StackLayout>
					</StackLayout>
				</ViewCell>
			</DataTemplate>
		</ListView.ItemTemplate>
	</ListView>
</StackLayout>
```


I was able to fix the problem by making a custom CellViewRenderer that sets the layout to zero:
```
public class FixedViewCellRenderer : ViewCellRenderer
{
	public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
	{
		var res = base.GetCell(item, reusableCell, tv);
		res.LayoutMargins = UIEdgeInsets.Zero;
		return res;
	}
}
```
Comment 1 Rui Marinho 2016-12-20 23:03:32 UTC
Thank you for taking the time to submit this report. After reviewing the description of this bug, we believe it no longer affects the current version of Xamarin.Forms. If you are still experiencing the issue after updating your packages, please reopen this report with an attached reproduction. 

For your convenience, we have created some reproduction best practices viewable here: https://gist.github.com/jassmith/92405c300e54a01dcc6d

Warm regards, 
Xamarin Forms Team