【问题标题】:Carousel Page navigation轮播页面导航
【发布时间】:2020-03-26 15:10:58
【问题描述】:

我只是想问一下轮播页面的流向。我知道 Carousel View 可以选择流向,但我似乎无法找到 carousel 页面具有相同的选项。 所以我试图想出一些可以解决我的问题的东西。 我有一个带有 2 个按钮的主页,其中一个将我带到 Carousel 1,向右滑动我得到 carousel 2,另一个到 carousel 2,向右滑动到 carousel 1。但是我被要求更改流程所以如果我去旋转木马 2,我向左滑动以获得旋转木马 1。

I have tried switch case but for some reason the first page doesnt load properly


     //    System.Threading.Thread.Sleep(500);
                //    //model.Busy = false;
                //    Device.BeginInvokeOnMainThread(async () =>
                //    {
                //        switch (_pages)
                //        {
                //            case Pages.Reading:
                //                await Navigation.PushAsync(new CarouselLearning(false), false);
                //                break;
                //            case Pages.Listening:
                //                await Navigation.PushAsync(new CarouselLearning(true), false);
                //                break;

                //        }
                //        Navigation.RemovePage(this);
                //    });
                //});

and then i tried just simple navigation which of course dosent work
 private async void OnListeningButtonClicked(object sender, EventArgs e) 
        {
            await Navigation.PushAsync(new CarouselLearning(Listening));
        }

你有这方面的经验吗?

【问题讨论】:

标签: xamarin.forms


【解决方案1】:

Carousel Page中,通过设置CurrentPage,选择去轮播1或者轮播2,例如:

public MainPageCS(bool isReading) {

    var greenContentPage = new ContentPage
    {
        Padding = padding,
        Content = new StackLayout {
        ...
    }
    };
    var blueContentPage = new ContentPage
    {
        Padding = padding,
        Content = new StackLayout {
        ...
    }
    };

    Children.Add(blueContentPage );
    Children.Add(greenContentPage);

    if (isReading)
    {
        this.CurrentPage = greenContentPage;
    }
    else
    {
        this.CurrentPage = blueContentPage ;
    }
}

如果您转到轮播 1,则向右滑动以转到轮播 2,如果您转到轮播 2,则向左滑动以转到轮播 1。

顺便说一句,你也可以使用CarouselView来实现你想要的。

导航到CarouselLearning 页面时,将CurrentItem 设置为轮播1 或轮播2。

或者使用 CarouselView 的FlowDirection

【讨论】: