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
40 changes: 39 additions & 1 deletion src/Controls/src/Core/IndicatorView/IndicatorStackLayout.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Microsoft.Maui.Controls.Shapes;
using Microsoft.Maui.Graphics;

Expand Down Expand Up @@ -161,10 +165,44 @@ void BindIndicatorItems()
}
});

BindableLayout.SetItemsSource(this, _indicatorView.ItemsSource);
// Get the filtered items source based on MaximumVisible
var itemsSource = GetFilteredItemsSource();
BindableLayout.SetItemsSource(this, itemsSource);

BindableLayout.SetItemTemplate(this, indicatorTemplate);
}

IEnumerable? GetFilteredItemsSource()
{
if (_indicatorView.ItemsSource is null || _indicatorView.MaximumVisible <= 0)
{
return null;
}

var itemsSource = _indicatorView.ItemsSource;
int totalCount = itemsSource is ICollection col
? col.Count
: itemsSource.Cast<object>().Count();

if (totalCount <= _indicatorView.MaximumVisible)
{
return itemsSource;
}

var filteredItems = new List<object>(_indicatorView.MaximumVisible);
foreach (var item in itemsSource)
{
if (filteredItems.Count >= _indicatorView.MaximumVisible)
{
break;
}

filteredItems.Add(item);
}

return filteredItems;
}

public void Remove()
{
_indicatorView.PropertyChanged -= IndicatorViewPropertyChanged;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 57 additions & 0 deletions src/Controls/tests/TestCases.HostApp/Issues/Issue31145.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
namespace Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 31145, "MaximumVisible Property Not Working with IndicatorTemplate in IndicatorView", PlatformAffected.All)]
public class Issue31145 : ContentPage
{
public Issue31145()
{
Label descriptionLabel = new Label
{
Text = "The test passes if the IndicatorView with an IndicatorTemplate respects the MaximumVisible property; otherwise, it fails.",
FontSize = 18,
HorizontalOptions = LayoutOptions.Center,
};

IndicatorView indicatorView = new IndicatorView
{
ItemsSource = new List<string> { "Item1", "Item2", "Item3", "Item4", "Item5" },
IndicatorColor = Colors.Yellow,
SelectedIndicatorColor = Colors.Gray,
HorizontalOptions = LayoutOptions.Center
};

indicatorView.IndicatorTemplate = new DataTemplate(() =>
{
return new BoxView
{
WidthRequest = 10,
HeightRequest = 10,
HorizontalOptions = LayoutOptions.Center,
VerticalOptions = LayoutOptions.Center
};
});

Button updateMaximumVisibleBtn = new Button
{
AutomationId = "UpdateMaximumVisibleBtn",
Text = "Set MaximumVisible Property to 2"
};

updateMaximumVisibleBtn.Clicked += (s, e) =>
{
indicatorView.MaximumVisible = 2;
};

Content = new StackLayout
{
Padding = 20,
Spacing = 20,
Children =
{
descriptionLabel,
indicatorView,
updateMaximumVisibleBtn
}
};
}
}
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 Issue31145 : _IssuesUITest
{
public Issue31145(TestDevice device) : base(device)
{
}

public override string Issue => "MaximumVisible Property Not Working with IndicatorTemplate in IndicatorView";

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