From f5d6ea8e036cae7229555dddac6b04cfffbcd12a Mon Sep 17 00:00:00 2001 From: Vladislav Antonyuk Date: Fri, 24 Nov 2023 11:28:45 +0200 Subject: [PATCH] IndicatorView IndicatorTemplate Binding --- .../Controls.Sample/Pages/Controls/IndicatorPage.xaml | 9 ++++++++- .../src/Core/IndicatorView/IndicatorStackLayout.cs | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Controls/samples/Controls.Sample/Pages/Controls/IndicatorPage.xaml b/src/Controls/samples/Controls.Sample/Pages/Controls/IndicatorPage.xaml index 92dce624ad2d..5b9ae2c63a9c 100644 --- a/src/Controls/samples/Controls.Sample/Pages/Controls/IndicatorPage.xaml +++ b/src/Controls/samples/Controls.Sample/Pages/Controls/IndicatorPage.xaml @@ -121,7 +121,14 @@ x:Name="indicatorView" IndicatorColor="LightGray" SelectedIndicatorColor="DarkGray" - HorizontalOptions="Center" /> + HorizontalOptions="Center"> + + + + + diff --git a/src/Controls/src/Core/IndicatorView/IndicatorStackLayout.cs b/src/Controls/src/Core/IndicatorView/IndicatorStackLayout.cs index 296e2816dceb..55c9b5090fe2 100644 --- a/src/Controls/src/Core/IndicatorView/IndicatorStackLayout.cs +++ b/src/Controls/src/Core/IndicatorView/IndicatorStackLayout.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Specialized; using System.ComponentModel; +using System.Linq; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls @@ -125,6 +126,7 @@ void AddExtraIndicatorItems() var indicatorTemplate = _indicatorView.IndicatorTemplate; var oldCount = Children.Count; + var items = _indicatorView.ItemsSource.Cast().ToArray(); for (var i = 0; i < indicatorCount - oldCount && i < indicatorMaximumVisible - oldCount; i++) { var size = indicatorSize > 0 ? indicatorSize : 10; @@ -139,6 +141,7 @@ void AddExtraIndicatorItems() HeightRequest = size, CornerRadius = _indicatorView.IndicatorsShape == IndicatorShape.Circle ? (float)size / 2 : 0 }; + indicator.BindingContext = items[i]; var tapGestureRecognizer = new TapGestureRecognizer(); tapGestureRecognizer.Tapped += (sender, args) => _indicatorView.Position = Children.IndexOf(sender as View); indicator.GestureRecognizers.Add(tapGestureRecognizer);