protected override void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                if (prevBtn != null)
                {
                    prevBtn.Click -= PrevBtn_Click;
                    prevBtn.Dispose();
                    prevBtn = null;
                }

                if (nextBtn != null)
                {
                    nextBtn.Click -= NextBtn_Click;
                    nextBtn.Dispose();
                    nextBtn = null;
                }

                if (indicators != null)
                {
                    indicators.Dispose();
                    indicators = null;
                }

                if (viewPager != null)
                {
                    viewPager.PageSelected           -= ViewPager_PageSelected;
                    viewPager.PageScrollStateChanged -= ViewPager_PageScrollStateChanged;

                    if (viewPager.Adapter != null)
                    {
                        viewPager.Adapter.Dispose();
                    }

                    viewPager.Dispose();
                    viewPager = null;
                }

                if (Element != null)
                {
                    Element.SizeChanged -= Element_SizeChanged;
                    if (Element.ItemsSource != null && Element.ItemsSource is INotifyCollectionChanged)
                    {
                        ((INotifyCollectionChanged)Element.ItemsSource).CollectionChanged -= ItemsSource_CollectionChanged;
                    }
                }

                _disposed = true;
            }

            try
            {
                base.Dispose(disposing);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
Exemplo n.º 2
0
        void CleanUpViewPager()
        {
            if (indicators != null)
            {
                indicators.Dispose();
                indicators = null;
            }

            if (viewPager != null)
            {
                viewPager.PageSelected           -= ViewPager_PageSelected;
                viewPager.PageScrollStateChanged -= ViewPager_PageScrollStateChanged;

                if (viewPager.Adapter != null)
                {
                    viewPager.Adapter.Dispose();
                }
                viewPager.Dispose();
                viewPager = null;
            }
        }