Skip to content

Commit

Permalink
IndicatorView IndicatorTemplate Binding
Browse files Browse the repository at this point in the history
  • Loading branch information
VladislavAntonyuk committed Nov 24, 2023
1 parent 01afe33 commit f5d6ea8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@
x:Name="indicatorView"
IndicatorColor="LightGray"
SelectedIndicatorColor="DarkGray"
HorizontalOptions="Center" />
HorizontalOptions="Center">
<IndicatorView.IndicatorTemplate>
<DataTemplate>
<Label
Text="{Binding }"/>
</DataTemplate>
</IndicatorView.IndicatorTemplate>
</IndicatorView>
</StackLayout>
</Grid>
</views:BasePage.Content>
Expand Down
3 changes: 3 additions & 0 deletions src/Controls/src/Core/IndicatorView/IndicatorStackLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +126,7 @@ void AddExtraIndicatorItems()
var indicatorTemplate = _indicatorView.IndicatorTemplate;

var oldCount = Children.Count;
var items = _indicatorView.ItemsSource.Cast<object>().ToArray();
for (var i = 0; i < indicatorCount - oldCount && i < indicatorMaximumVisible - oldCount; i++)
{
var size = indicatorSize > 0 ? indicatorSize : 10;
Expand All @@ -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);
Expand Down

0 comments on commit f5d6ea8

Please sign in to comment.