Hello,
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()
{
InitializeComponent();
var timer = Application.Current.Dispatcher.CreateTimer();
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += (s, e) =>
{
MainThread.BeginInvokeOnMainThread(() =>
{
mainCarouselView.Position = (mainCarouselView.Position + 1) % ItemsSource.Count;
});
};
timer.Start();
}
}
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.