Net maui How to add sliding animation to Carousel with timer ?

Sami 861 Reputation points

Net maui How to add sliding animation to Carousel with timer ?

Platform android and ios

A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,176 questions
0 comments No comments
{count} votes

Accepted answer
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 71,836 Reputation points Microsoft Vendor


    protected override async void OnAppearing() is not accepted C# side and position also is not working that missing something?

    If you add <CarouselView> in the ContentView, you can add CreateTimer to the ContentView's background code. You can change the current items by mainCarouselView.Position, then get the itemsource's count like following code

    public partial class MyView : ContentView
       public static readonly BindableProperty ItemsSourceProperty =
                  BindableProperty.Create(nameof(ItemsSource), typeof(ObservableCollection<string>), typeof(MyView));
       public ObservableCollection<string> ItemsSource
            get => (ObservableCollection<string>)GetValue(ItemsSourceProperty);
            set => SetValue(ItemsSourceProperty, value);
        public MyView()
            var timer = Application.Current.Dispatcher.CreateTimer();
            timer.Interval = TimeSpan.FromSeconds(1);
            timer.Tick += (s, e) =>
                MainThread.BeginInvokeOnMainThread(() =>
                    mainCarouselView.Position = (mainCarouselView.Position + 1) % ItemsSource.Count;

    Best Regards,

    Leon Lu

    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful