Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Margin and Padding don't work in CollectionView #23211

Open
acaliaro opened this issue Jun 24, 2024 · 14 comments
Open

[BUG] Margin and Padding don't work in CollectionView #23211

acaliaro opened this issue Jun 24, 2024 · 14 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView delighter migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@acaliaro
Copy link

Description

On iOS Margin and Padding don't work in CollectionView. In the attached example, I have 3 collection views.

  • In the first, a grid with padding appears to maintain padding correctly.

  • In the second, the grid with the margin does not maintain the margin: I would expect there to be white space around the grid but the blue color is continuous.

  • In the third (with border), it seems that the padding is replaced by a margin.

I have seen that in the past some bugs relating to these problems have already been opened, apparently resolved, but apparently not correctly

Steps to Reproduce

Run the project
presso "popup problem!!!!" button
a page with 3 collections should appears

Link to public reproduction project repository

https://github.com/acaliaro/MauiCollectionViewPaddingProblems

Version with bug

8.0.60 SR6

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI, Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS 17.3 iphone 12

Did you find any workaround?

I think this could help #17885 (comment)

Relevant log output

No response

@acaliaro acaliaro added the t/bug Something isn't working label Jun 24, 2024
Copy link
Contributor

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@Zhanglirong-Winnie Zhanglirong-Winnie added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert labels Jun 24, 2024
@Zhanglirong-Winnie
Copy link

This issue has been verified using Visual Studio 17.11.0 Preview 2.1 (8.0.40 & 8.0.60 & 8.0.14). Can be reproduced on iOS platform.

@PureWeen PureWeen added the potential-regression This issue described a possible regression on a currently supported version., verification pending label Jun 24, 2024
@PureWeen PureWeen added this to the Backlog milestone Jun 24, 2024
@PureWeen PureWeen added the area-controls-collectionview CollectionView, CarouselView, IndicatorView label Jun 24, 2024
@acaliaro

This comment was marked as off-topic.

@jfversluis

This comment was marked as off-topic.

@acaliaro

This comment was marked as off-topic.

@jfversluis

This comment was marked as off-topic.

@samhouts samhouts removed s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Jul 3, 2024
@acaliaro
Copy link
Author

@samhouts Hi. Any news about this?

@samhouts samhouts added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed delighter-sc labels Jul 10, 2024
@kiddailey
Copy link

kiddailey commented Jul 24, 2024

Just to document my experience because this isn't limited to iOS. I have the same issue on Windows.

I have a Border view directly in a collection view DataTemplate and the Margin values have no affect at all on Windows. I'm trying to add a Border to each item in the CollectionView and add spacing in between them.

For example, the Margins on the Border in this example are completely ignored (although the Padding does work):

<CollectionView.ItemTemplate>
    <DataTemplate>
        <Border Margin="0,0,0,10" Padding="10,5"> ... </Border>
    </DataTemplate>
</CollectionView.ItemTemplate>

If I simply wrap the Border in a Grid (or any other type of container View) without changing anything else then the margins on the border suddenly work. For example:

<CollectionView.ItemTemplate>
    <DataTemplate>
        <Grid>
            <Border Margin="0,0,0,10" Padding="10,5"> ... </Border>
        </Grid>
    </DataTemplate>
</CollectionView.ItemTemplate>

It's worth noting that the obsolete Frame View also behaves this same way. Margins on Grids, Stacklayouts, etc work as expected.

@Domik234
Copy link

Domik234 commented Aug 7, 2024

Hey,
we've always used wrapping to ContentView to make it work even in Xamarin.Forms.

Currently I am doing it too and it works as expected for MAUI.

Using the padding or margin directly on root view in item template had always some problems depending on used platform.

@acaliaro
Copy link
Author

acaliaro commented Sep 6, 2024

there are some news about this issue? Will be moved on a sprint?

@acaliaro
Copy link
Author

Hi. Are there some news about this?

@RsZoli
Copy link

RsZoli commented Oct 9, 2024

Well if you are so fast on closing issues about key problems, i would also like to know the current state about this, because its blocking us to deploy on other platforms than Android!

@samhouts Please?

@IliyanPopov
Copy link

IliyanPopov commented Oct 31, 2024

i have encountered similar issue only on iOS when using collection view with observable collection and two way bindings.

My workaround is to use a grid and add a second row for example of 20 heigh and leave it blank in purpose:

			<CollectionView ItemsSource="{Binding Displays}"
				                SelectionMode="Single"
				                SelectedItem="{Binding Selection, Mode=TwoWay}"
				                HorizontalOptions="Fill" VerticalOptions="Fill">
					<CollectionView.ItemTemplate>
						<DataTemplate x:DataType="{x:Type viewModels:RedDisplayViewModel}">
							<Grid HorizontalOptions="Fill" VerticalOptions="Center" RowSpacing="10"
							      ColumnSpacing="8" HeightRequest="60">
								<Grid.RowDefinitions>
									<RowDefinition Height="*" />
									<RowDefinition Height="20" /> // Like so
								</Grid.RowDefinitions>
								<Grid.ColumnDefinitions>

@Domik234
Copy link

Hey @IliyanPopov,

I believe that wrapping into ContentView should be performance more efficient than Grid.

<!-- ContentView acts only as a wrapper. It allows to use margin and padding in it's Content property -> Do not set margin and padding here -->
<ContentView> 
<!-- Set margin and padding here -->
<.... /> 
</ContentView>

Note: <.... /> = Any view or layout

Example: I need to have grid in CollectionView with margin 8.
<ContentView>
    <Grid Margin="8" />
</ContentView>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView delighter migration-compatibility Xamarin.Forms to .NET MAUI Migration, Upgrade Assistant, Try-Convert platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

9 participants