Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] [UWP] GridItemsLayout.HorizontalItemSpacing adds spacing to edges #9851

Open
Eli-Black-Work opened this issue Mar 5, 2020 · 4 comments

Comments

@Eli-Black-Work
Copy link

Eli-Black-Work commented Mar 5, 2020

Description

On UWP, when setting GridItemsLayout.HorizontalItemSpacing or GridItemsLayout.VerticalItemSpacing, spacing is applied not only between elements in the grid but also around the edges of the grid.

Steps to Reproduce

Given this XAML:

<StackLayout>
	<SearchBar ... />

	<CollectionView ItemsSource="...">
		<CollectionView.ItemsLayout>
			<GridItemsLayout Orientation="Vertical" Span="4" HorizontalItemSpacing="5" VerticalItemSpacing="5" />
		</CollectionView.ItemsLayout>
		<CollectionView.ItemTemplate>
			<DataTemplate x:DataType="viewModels:ExistingPanelViewModel">
				<Frame BorderColor="Gray" Padding="8" CornerRadius="0">...</Frame>
			</DataTemplate>
		</CollectionView.ItemTemplate>
	</CollectionView>
</StackLayout>

The result is that not only does the 5pt of spacing get applied between items, but it also gets applied around the edges of the CollectionView. This makes it so that the CollectionView appears offset from the search bar that's above it:

Xamarin - spacing issues

###Workaround

In my case, this spacing is undesired, but it's kind of annoying to get rid of :) One approach is to apply a negative margin to the entire CollectionView, but this means that the negative margin also affects CollectionView.EmptyView, CollectionView.Header, and CollectionView.Footer, so then we have to add margin to those elements to compensate:

<StackLayout>
	<SearchBar ... />

	<CollectionView ItemsSource="..." Margin="-5,0,-5,0">
		<CollectionView.ItemsLayout>
			<GridItemsLayout Orientation="Vertical" Span="4" HorizontalItemSpacing="5" VerticalItemSpacing="5" />
		</CollectionView.ItemsLayout>
		<CollectionView.ItemTemplate>
			<DataTemplate x:DataType="viewModels:ExistingPanelViewModel">
				<Frame BorderColor="Gray" Padding="8" CornerRadius="0">...</Frame>
			</DataTemplate>
		</CollectionView.ItemTemplate>
	</CollectionView>
	<CollectionView.EmptyView>
		<StackLayout Padding="5,0,5,0">
			<Label Text="Empty view" />
		</StackLayout>
	</CollectionView.EmptyView>
	<CollectionView.Header>
		<StackLayout Padding="5,0,5,0">
			<Label Text="Header view" />
		</StackLayout>
	</CollectionView.Header>
	<CollectionView.Footer>
		<StackLayout Padding="5,0,5,0">
			<Label Text="Footer view" />
		</StackLayout>
	</CollectionView.Footer>
</StackLayout>

Basic Information

  • Version with issue: Xamarin.Forms 4.5
  • IDE: VS 2019
  • Environment: UWP (I haven't tested this on other platforms)
@Eli-Black-Work Eli-Black-Work added s/unverified New report that has yet to be verified t/bug 🐛 labels Mar 5, 2020
@pauldipietro pauldipietro added this to New in Triage Mar 5, 2020
@Eli-Black-Work
Copy link
Author

If backwards compatibility isn't an issue, then my suggestion for fixing this would be to have GridItemsLayout.HorizontalItemSpacing/GridItemsLayout.VerticalItemSpacing only apply spacing between elements in the grid and not apply spacing around the edges of the grid. Then, introduce a a Margin attribute for GridItemsLayout that takes care of applying margin around the edges of the grid.

@hartez hartez added p/UWP a/collectionview e/4 🕓 4 and removed s/unverified New report that has yet to be verified labels Mar 7, 2020
@hartez hartez added this to Backlog in CollectionView via automation Mar 7, 2020
@hartez hartez removed this from New in Triage Mar 7, 2020
@hartez
Copy link
Contributor

hartez commented Mar 7, 2020

ItemSpacing shouldn't be applied to the leading/trailing edges.

@Eli-Black-Work
Copy link
Author

Okay, good to know, thanks. I was seeing this on UWP, so maybe it's specific to that platform. Let me update the bug's description :)

@Eli-Black-Work Eli-Black-Work changed the title [Bug] GridItemsLayout HorizontalItemSpacing shouldn't add spacing to edges [Bug] [UWP] GridItemsLayout.HorizontalItemSpacing adds spacing to edges Mar 9, 2020
@YZahringer
Copy link
Contributor

Related to #10547?

@samhouts samhouts added this to the 5.0.0 milestone Aug 13, 2020
@samhouts samhouts added this to To do in vNext+1 (5.0.0) Aug 14, 2020
@samhouts samhouts removed this from the 5.0.0 milestone Nov 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
CollectionView
  
Review Backlog
Development

No branches or pull requests

4 participants