diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/IndicatorViewWithTemplatedIcon.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/IndicatorViewWithTemplatedIcon.png new file mode 100644 index 000000000000..b6d61ae69ccb Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/IndicatorViewWithTemplatedIcon.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue7144.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue7144.cs new file mode 100644 index 000000000000..702dbfd84ab2 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue7144.cs @@ -0,0 +1,78 @@ +using System.Collections.ObjectModel; + +namespace Controls.TestCases.HostApp.Issues; + +[Issue(IssueTracker.Github, 7144, "IndicatorView using templated icons not working", PlatformAffected.UWP)] +public class Issue7144 : ContentPage +{ + ObservableCollection Items { get; set; } = new ObservableCollection() { "Item1", "Item2" }; + + public Issue7144() + { + Grid grid = new Grid(); + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Star }); + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); + + IndicatorView indicatorViewWithDataTemplate = new IndicatorView + { + Margin = new Thickness(0, 0, 0, 40), + HorizontalOptions = LayoutOptions.Center, + IndicatorColor = Colors.Black, + SelectedIndicatorColor = Colors.Green + }; + + indicatorViewWithDataTemplate.IndicatorTemplate = new DataTemplate(() => + { + Image image = new Image() + { + Source = "dotnet_bot.png", + HeightRequest = 15, + WidthRequest = 15, + }; + return image; + }); + + CarouselView carouselView = new CarouselView + { + ItemsSource = Items, + Loop = false, + IndicatorView = indicatorViewWithDataTemplate, + ItemTemplate = new DataTemplate(() => + { + StackLayout stackLayout = new StackLayout(); + + Label label = new Label + { + FontAttributes = FontAttributes.Bold, + FontSize = 24, + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + label.SetBinding(Label.TextProperty, ".");; + + stackLayout.Children.Add(label); + + return stackLayout; + }) + }; + + Label label = new Label + { + AutomationId = "descriptionLabel", + Text = "The test case fails if the IndicatorView DataTemplate is not displayed", + FontAttributes = FontAttributes.Bold, + FontSize = 24, + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + }; + + grid.Add(carouselView, 0, 0); + grid.Add(indicatorViewWithDataTemplate, 0, 1); + grid.Add(label, 0, 2); + + Content = grid; + } +} + + diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/IndicatorViewWithTemplatedIcon.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/IndicatorViewWithTemplatedIcon.png new file mode 100644 index 000000000000..644af07f668b Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/IndicatorViewWithTemplatedIcon.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue7144.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue7144.cs new file mode 100644 index 000000000000..97077afeb5f9 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue7144.cs @@ -0,0 +1,22 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue7144 : _IssuesUITest +{ + public Issue7144(TestDevice device) : base(device) + { + } + + public override string Issue => "IndicatorView using templated icons not working"; + + [Test] + [Category(UITestCategories.IndicatorView)] + public void IndicatorViewWithTemplatedIcon() + { + App.WaitForElement("descriptionLabel"); + VerifyScreenshot(); + } +} diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/IndicatorViewWithTemplatedIcon.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/IndicatorViewWithTemplatedIcon.png new file mode 100644 index 000000000000..24062bf0a47e Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/IndicatorViewWithTemplatedIcon.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/IndicatorViewWithTemplatedIcon.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/IndicatorViewWithTemplatedIcon.png new file mode 100644 index 000000000000..bb70a7ca7070 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/IndicatorViewWithTemplatedIcon.png differ diff --git a/src/Core/src/Platform/Windows/MauiPageControl.cs b/src/Core/src/Platform/Windows/MauiPageControl.cs index a9f643bd760a..6ef6ca0e4627 100644 --- a/src/Core/src/Platform/Windows/MauiPageControl.cs +++ b/src/Core/src/Platform/Windows/MauiPageControl.cs @@ -20,6 +20,8 @@ public class MauiPageControl : ItemsControl WBrush? _fillColor; ObservableCollection? _dots; + internal bool UseShapeIndicator => _indicatorView == null || (_indicatorView is ITemplatedIndicatorView templatedView && templatedView.IndicatorsLayoutOverride != null); + public MauiPageControl() { HorizontalAlignment = Microsoft.UI.Xaml.HorizontalAlignment.Center; @@ -35,15 +37,17 @@ public void SetIndicatorView(IIndicatorView indicatorView) } internal void UpdateIndicatorsColor() - { - if (_indicatorView == null) + { + if (UseShapeIndicator) + { return; + } - if (_indicatorView.IndicatorColor is SolidPaint solidPaint) + if (_indicatorView?.IndicatorColor is SolidPaint solidPaint) _fillColor = solidPaint?.ToPlatform(); - if (_indicatorView.SelectedIndicatorColor is SolidPaint selectedSolidPaint) + if (_indicatorView?.SelectedIndicatorColor is SolidPaint selectedSolidPaint) _selectedColor = selectedSolidPaint.ToPlatform(); - var position = _indicatorView.Position; + var position = _indicatorView?.Position; int i = 0; foreach (var item in Items) { @@ -54,13 +58,15 @@ internal void UpdateIndicatorsColor() internal void CreateIndicators() { - if (_indicatorView == null) + if (UseShapeIndicator) + { return; + } var position = GetIndexFromPosition(); var indicators = new List(); - var indicatorCount = _indicatorView.GetMaximumVisible(); + var indicatorCount = _indicatorView?.GetMaximumVisible(); if (indicatorCount > 0) { for (int i = 0; i < indicatorCount; i++)