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 @@ -87,6 +87,7 @@ protected override void UpdateItemTemplate()
return;

ListViewBase.ItemTemplate = CarouselItemsViewTemplate;
UpdateItemsSource();
}

protected override void OnScrollViewerFound(ScrollViewer scrollViewer)
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
98 changes: 98 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue29462.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
using System.Collections.ObjectModel;

namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 29462, "CarouselView ItemTemplate Not Updating at Runtime", PlatformAffected.UWP)]
public class Issue29462 : ContentPage
{
public Issue29462()
{
var verticalStackLayout = new VerticalStackLayout();
var carouselItems = new ObservableCollection<string>
{
"Item 0",
"Item 1",
"Item 2",
"Item 3",
"Item 4",
};

CarouselView2 carouselView = new CarouselView2
{
ItemsSource = carouselItems,
ItemsUpdatingScrollMode = ItemsUpdatingScrollMode.KeepScrollOffset,
HeightRequest = 300,
Loop = false,
HorizontalScrollBarVisibility = ScrollBarVisibility.Never,
ItemTemplate = new DataTemplate(() =>
{
var grid = new Grid
{
Padding = 10
};

var label = new Label
{
VerticalOptions = LayoutOptions.Center,
HorizontalOptions = LayoutOptions.Center,
FontSize = 18,
};
label.SetBinding(Label.TextProperty, ".");
label.SetBinding(Label.AutomationIdProperty, ".");

grid.Children.Add(label);
return grid;
}),
HorizontalOptions = LayoutOptions.Fill,
};

var indicatorView = new IndicatorView
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
carouselView.IndicatorView = indicatorView;

var itemTempateButton = new Button
{
Text = "Change Item Template",
AutomationId = "ChangeItemTemplate",
Margin = new Thickness(20),
};

itemTempateButton.Clicked += (sender, e) =>
{
carouselView.ItemTemplate = new DataTemplate(() =>
{
Grid grid = new Grid
{
BackgroundColor = Colors.LightGray,
HeightRequest = 200,
WidthRequest = 300,
Margin = new Thickness(10)
};

var label = new Label
{
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center,
FontSize = 24,
TextColor = Colors.DarkBlue
};

label.SetBinding(Label.TextProperty, new Binding(".")
{
StringFormat = "{0} (Grid Template)"
});

grid.Children.Add(label);
return grid;
});
};

verticalStackLayout.Children.Add(carouselView);
verticalStackLayout.Children.Add(indicatorView);
verticalStackLayout.Children.Add(itemTempateButton);
Content = verticalStackLayout;
}
}
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 Issue29462 : _IssuesUITest
{
public override string Issue => "CarouselView ItemTemplate Not Updating at Runtime";

public Issue29462(TestDevice device)
: base(device)
{ }

[Test]
[Category(UITestCategories.CarouselView)]
public void TestDynamicItemTemplateChangeInCarouselView()
{
App.WaitForElement("ChangeItemTemplate");
App.Tap("ChangeItemTemplate");
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