void OnPageAppearing(object sender, EventArgs args)
        {
            ContentPage          page          = (ContentPage)sender;
            StackLayout          layout        = (StackLayout)page.Content;
            ElottieAnimationView animationView = (ElottieAnimationView)layout.Children[0];

            animationView.Play();
        }
        void OnPageDisappearing(object sender, EventArgs args)
        {
            ContentPage          page          = (ContentPage)sender;
            StackLayout          layout        = (StackLayout)page.Content;
            ElottieAnimationView animationView = (ElottieAnimationView)layout.Children[0];

            if (animationView.IsPlaying)
            {
                animationView.Stop();
            }
        }
Esempio n. 3
0
        public MainPageCS()
        {
            ItemTemplate = new DataTemplate(() =>
            {
                var animationView = new ElottieAnimationView
                {
                    AutoRepeat        = true,
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions   = LayoutOptions.FillAndExpand
                };
                animationView.SetBinding(ElottieAnimationView.AnimationFileProperty, "AnimationFile");

                var contentPage = new ContentPage
                {
                    Content = new StackLayout
                    {
                        Children = { animationView }
                    }
                };

                contentPage.Appearing += (s, e) =>
                {
                    animationView.Play();
                };

                contentPage.Disappearing += (s, e) =>
                {
                    if (animationView.IsPlaying)
                    {
                        animationView.Stop();
                    }
                };

                return(contentPage);
            });
            ItemsSource = LottieDataModel.All;
        }