Hello,
Im using SfRotator in XAML, im trying to bind the SelectedIndex property to my MVVM ViewModel, but whenever i swipe the SfRotator, it doesnt execute the logic in my mv
<rotator:SfRotator ItemsSource="{Binding Tutorials}" SelectedIndex="{Binding CurrentTutorialIndex}" DotPlacement="None" VerticalOptions="FillAndExpand">
<rotator:SfRotator.ItemTemplate>
<DataTemplate>
<Frame HeightRequest="300" Padding="0">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="8*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Image Source="{Binding image}" Aspect="AspectFill" Grid.Row="0" BackgroundColor="Orange"></Image>
<Button FontFamily="{StaticResource FontAwesomeSolid}" Text="Démarrez l'application " IsVisible="{Binding Source={x:Reference MyTutorialsPage} , Path=BindingContext.CanStartApp}" Command="{Binding Source={x:Reference MyTutorialsPage} , Path=BindingContext.StartAppCommand}" CornerRadius="8" Grid.Row="1"></Button>
</Grid>
</Frame>
</DataTemplate>
</rotator:SfRotator.ItemTemplate>
</rotator:SfRotator>
This is my ViewModel:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace My_APP.ViewModels
{
public class TutorialViewModel : BaseViewModel
{
public ObservableCollection<Tutorial> Tutorials { get; set; }
public bool CanStartApp { get; set; }
private int _CurrentTutorialIndex;
public int CurrentTutorialIndex
{
get { return _CurrentTutorialIndex; }
set
{
if(value < Tutorials.Count - 1)
{
_CurrentTutorialIndex = value;
CanStartApp = false;
OnPropertyChanged(nameof(CanStartApp));
}
else
{
_CurrentTutorialIndex = value;
CanStartApp = true;
OnPropertyChanged(nameof(CanStartApp));
}
}
}
public Command StartAppCommand { get; }
public TutorialViewModel()
{
Tutorials = new ObservableCollection<Tutorial>();
StartAppCommand = new Command(async () => await StartApp());
CurrentTutorialIndex = 0;
OnPropertyChanged(nameof(CurrentTutorialIndex));
CanStartApp = false;
OnPropertyChanged(nameof(CanStartApp));
Tutorials.Add(new Tutorial { image = "tutorial_001" });
Tutorials.Add(new Tutorial { image = "tutorial_002" });
Tutorials.Add(new Tutorial { image = "tutorial_003" });
Tutorials.Add(new Tutorial { image = "tutorial_004" });
}
async Task StartApp()
{
await PopupNavigation.PopAsync();
}
}
}