SfRotator's SelectedIndex binding (MVVM) not working

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 &#xf35a;" 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();
        }
    }
}


3 Replies 1 reply marked as answer

SS Suganya Sethuraman Syncfusion Team September 28, 2020 06:45 AM UTC

Hi Fodil,

Greetings from Syncfusion.

We have tried to replicate the reported issue “SfRotator's SelectedIndex binding (MVVM) not working” at our end, we are afraid that we are not able to reproduce the issue at our end. We have attached sample for your reference.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/SfRotatorSample-1547717397

Since we are not aware of your exact application scenario, we were not able to reproduce this issue at our end, so can you please provide complete runnable sample. This will be helpful for us to investigate further and provide you a better solution at the earliest.

Regards,
Suganya Sethuraman.  
 



RK Radoslaw Kubas October 21, 2020 07:20 AM UTC

Hello,

I noticed this problem too, to fix just have to set binding this way:

SelectedIndex="{Binding SelectedIndex, Mode=TwoWay}"

Regards,
Radek

Marked as answer

SS Suganya Sethuraman Syncfusion Team October 22, 2020 04:53 AM UTC

Hi Radoslaw,

Thanks for the suggestion.

Regards,
Suganya Sethuraman.


Loader.
Up arrow icon