Skip to content

[Mac] Size is not correctly assigned in the CarouselView #15

@Ahamed-Ali

Description

@Ahamed-Ali

Description

I have a CarouselView with a datatemplate, in iOS, width is properly get and arranged properly, but in Mac Width is not properly assigned i think.

Below is the video of wrong behavior in mac carouselview

Actual in Mac

Wrongbehavior.mov

Expected in Mac

CorrectWidthBehavior.mov

Code Snippet



<Grid.Resources>

  <DataTemplate x:Key="SampleItemTemplate">
    <Grid 
      RowDefinitions="Auto, Auto"
      BackgroundColor="{Binding Color, Mode=OneWay}">
      <Label 
        TextColor="White"
        Text="{Binding Title, Mode=OneWay}" 
        FontAttributes="Bold" />
      <Label 
        Grid.Row="1"
        TextColor="White"
        Text="{Binding Description, Mode=OneWay}" />
    </Grid>
  </DataTemplate>
  
</Grid.Resources>
<Label 
  AutomationId="WaitForStubControl"
  Text="Tap the Button to add an item"/>
<CarouselView 
  x:Name="TestCarouselView"
  Grid.Row="1"
  ItemTemplate="{StaticResource SampleItemTemplate}"
  Loop="True"
  HeightRequest="250"
  HorizontalOptions="Center"/>

<Button AutomationId="AddItemButton"
        Grid.Row="2"
        Text="Add Item"
        Clicked="OnAddItemClicked" />

using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues
{
[Issue(IssueTracker.Github, 22417, "[Windows] The list does not show newly added items", PlatformAffected.UWP)]
public partial class Issue22417 : ContentPage
{
ObservableCollection _exampleItems = new();

	public Issue22417()
	{
		InitializeComponent();

		_exampleItems.Add(new Issue22000Model("First", "First CarouselView item", Colors.Red));
		_exampleItems.Add(new Issue22000Model("Second", "Second CarouselView item", Colors.LightBlue));
		_exampleItems.Add(new Issue22000Model("Third", "Third CarouselView item", Colors.Pink));
		_exampleItems.Add(new Issue22000Model("Fourth", "Fourth CarouselView item", Colors.GreenYellow));
		_exampleItems.Add(new Issue22000Model("Fifth", "Fifth CarouselView item", Colors.Purple));

		TestCarouselView.ItemsSource = _exampleItems;
	}

	void OnAddItemClicked(object sender, EventArgs e)
	{
		_exampleItems.Add(new Issue22000Model("Sixth", "Sixth CarouselView item", Colors.CornflowerBlue));
		TestCarouselView.ScrollTo(5, animate: false);
	}
}

}

Steps to Reproduce

No response

Link to public reproduction project repository

No response

Version with bug

Unknown/Other

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

macOS

Affected platform versions

Mac 15

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions