在启动时设置当前轮播页面。 Xamarin.Forms

时间:2018-03-20 10:53:16

标签: xamarin.forms carousel

我的CarouselPage有问题。初始化时,我指定CarouselPage.ItemSource = .... 一开始我需要显示第二页,而不是第一页。

我的代码:

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;

我该怎么做?

2 个答案:

答案 0 :(得分:0)

我认为(但我没有测试)你可以使用像

这样的东西
this.CurrentPage = this.Children[1];

答案 1 :(得分:0)

我做到了:

private bool _isInitialized;

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