Xamarin:轮播页面是否一次加载所有页面 [英] Xamarin: Does the carousel page load all the pages at one

查看:249
本文介绍了Xamarin:轮播页面是否一次加载所有页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Xamarin形式的新手。在Android上,我使用ViewPager加载图像,然后用户在页面上滑动。由于Android具有适配器,因此不会立即初始化所有视图。现在,我想转到Xamarin表格,然后看到轮播页面。它的行为是否与ViewPager仅根据需要加载页面相同?

I new in Xamarin form. On Android, I used ViewPager to load images and the user swipe around the pages. Since Android has adapter, all the views are not initialized at once. Now I want to move to Xamarin form and seeing there is Carousel Page. Does it behave the same as ViewPager only load pages as needed?

推荐答案

如果您阻止在构造函数的构造函数中调用InitializeComponent,

If you prevent the call to InitializeComponent in the constructor of the page you might have an effect on the load time.

public interface CarouselChildPage {
    void childAppearing();
    void childDissapearing();
}

public partial class MainPage : CarouselPage {
    CarouselPageChild previousPage;

    protected override void OnCurrentPageChanged() {
            base.OnCurrentPageChanged();
            if (previousPage != null)
                previousPage.childDissapearing();

            int index = Children.IndexOf(CurrentPage);
            CarouselPageChild childPage = Children[index] as CarouselPageChild;
            childPage.childAppearing();
            previousPage = childPage;
        }
}


public partial class FriendsListPage : ContentPage, CarouselPageChild {
        bool isLoaded = false;

        public FriendsListPage() {
                // Remove Initialise Component Here    
        }

        public void childAppearing() {
            Logger.log("My Appearing");
            if (!isLoaded){ 
                InitializeComponent();
                isLoaded = true;
            }
        }

        public void childDissapearing() {
            Logger.log("My Disappearing");
        }
}

这篇关于Xamarin:轮播页面是否一次加载所有页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆