Nikita Goncharuk
Nikita Goncharuk

Reputation: 815

Set Current Carousel Page on the startup. Xamarin.Forms

I have a problem with CarouselPage. When initializing, I assign CarouselPage.ItemSource = .... At start i need to show second page, not first.

My code:

Weeks = new ObservableCollection<Week>
                {
                    new Week {Days = GetDays(currentMonday.AddDays(-7)), ItemTappedCommand = JobTappedCommand},
                    new Week {Days = GetDays(currentMonday), ItemTappedCommand = JobTappedCommand},
                    new Week {Days = GetDays(currentMonday.AddDays(7)), ItemTappedCommand = JobTappedCommand},
                };

                CurrentDate = Weeks[1].DateOfFirstDayOfWeek;

How can I do this?

Upvotes: 0

Views: 447

Answers (2)

Nikita Goncharuk
Nikita Goncharuk

Reputation: 815

I make this:

private bool _isInitialized;

private void CarouselAllJobsWeekPage_OnPagesChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (!_isInitialized
                && Children.Count > 2)
            {
                CurrentPage = this.Children[1];
                _isInitialized = true;
            }
        }

Upvotes: 0

Alessandro Caliaro
Alessandro Caliaro

Reputation: 5768

I think (but I have not test) you can use something like

this.CurrentPage = this.Children[1];

Upvotes: 0

Related Questions