Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ protected override void DisconnectHandler(ListViewBase platformView)

protected override void UpdateItemsSource()
{
var itemsSource = ItemsView?.ItemsSource;

if (itemsSource == null)
return;

var itemTemplate = ItemsView?.ItemTemplate;

if (itemTemplate == null)
Expand Down Expand Up @@ -141,7 +136,7 @@ protected override ItemsViewScrolledEventArgs ComputeVisibleIndexes(ItemsViewScr
{
args = base.ComputeVisibleIndexes(args, orientation, advancing);

if (ItemsView.Loop)
if (ItemsView.Loop && ItemsView.ItemsSource is not null)
{
args.FirstVisibleItemIndex %= ItemCount;
args.CenterItemIndex %= ItemCount;
Expand Down Expand Up @@ -505,6 +500,9 @@ void CarouselScrolled(object sender, ItemsViewScrolledEventArgs e)

void OnScrollViewChanging(object sender, ScrollViewerViewChangingEventArgs e)
{
if (ItemsView.ItemsSource is null)
return;

ItemsView.SetIsDragging(true);
ItemsView.IsScrolling = true;
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29472.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace Controls.TestCases.HostApp.Issues;

[Issue(IssueTracker.Github, 29472, "ItemsSource is not dynamically cleared in the CarouselView", PlatformAffected.UWP)]
public class Issue29472 : ContentPage
{
public Issue29472()
{
Label descriptionLabel = new Label
{
Text = "The test passes if the previously bound items are cleared from the view when the ItemsSource is dynamically set to null; otherwise, it fails.",
FontSize = 16,
HorizontalOptions = LayoutOptions.Center
};

CarouselView carouselView = new CarouselView
{
ItemsSource = new List<string> { "Item1", "Item2" },
Loop = false,
ItemTemplate = new DataTemplate(() =>
{
Label label = new Label
{
FontSize = 24,
BackgroundColor = Colors.LightGray,
Margin = new Thickness(10)
};

label.SetBinding(Label.TextProperty, ".");
return label;
}),
};

Button clearItemsSource = new Button
{
AutomationId = "ClearItemsSourceBtn",
Text = "Set the ItemsSource of the CarouselView to null",
HorizontalOptions = LayoutOptions.Center
};

clearItemsSource.Clicked += (s, e) =>
{
carouselView.ItemsSource = null;
};

Grid grid = new Grid
{
Padding = 20,
RowSpacing = 15,
RowDefinitions =
{
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Auto },
new RowDefinition { Height = GridLength.Star },
}
};

grid.Add(descriptionLabel, 0, 0);
grid.Add(clearItemsSource, 0, 1);
grid.Add(carouselView, 0, 2);

Content = grid;
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue29472 : _IssuesUITest
{
public Issue29472(TestDevice device) : base(device)
{
}

public override string Issue => "ItemsSource is not dynamically cleared in the CarouselView";

[Test]
[Category(UITestCategories.CarouselView)]
public void VerifyCarouselViewItemsSourceClearedDynamically()
{
App.WaitForElement("ClearItemsSourceBtn");
App.Tap("ClearItemsSourceBtn");
VerifyScreenshot();
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading