Example #1
0
        protected override void OnElementChanged(ElementChangedEventArgs <Flip> e)
        {
            base.OnElementChanged(e);
            if (e.OldElement != null)
            {
                e.OldElement.Children.CollectionChanged -= this.Children_CollectionChanged;
                e.OldElement.NextRequired  -= this.Element_NextRequired;
                e.OldElement.IndexRequired -= this.Element_IndexRequired;
            }

            if (this.Element == null)
            {
                return;
            }

            var Root = new AW.RelativeLayout(this.Context);

            this.VP = new ViewPager(this.Context);
            this.VP.PageSelected += VP_PageSelected;

            //如果传入的 items 是 IEnumerable 类型的 (未ToList) , 会一直去计算那个 IEnumerable , 可断点到 GetChildrenViews 里, 会一直在那里执行, 从而导致子视图不显示
            this.Adapter = new FlipViewAdapter(this.VP);
            Adapter.SetItems(this.GetChildrenViews().ToList());
            Adapter.PosChanged += Adapter_PosChanged;
            this.VP.Adapter     = Adapter;
            this.VP.AddOnPageChangeListener(Adapter);
            Root.AddView(this.VP, LayoutParams.MatchParent, LayoutParams.MatchParent);

            this.PointsContainer             = new LinearLayout(this.Context);
            this.PointsContainer.Orientation = Orientation.Horizontal;

            var lp = new AW.RelativeLayout.LayoutParams(LayoutParams.WrapContent, 20);

            lp.AddRule(LayoutRules.AlignParentBottom);
            lp.AddRule(LayoutRules.CenterHorizontal);
            Root.AddView(this.PointsContainer, lp);

            this.SetNativeControl(Root);

            if (this.Element.ShowIndicator)
            {
                this.SetPoints();
            }

            Root.Invalidate();
            Root.RequestLayout();

            this.Element.NextRequired  += Element_NextRequired;
            this.Element.IndexRequired += Element_IndexRequired;

            this.Element.Children.CollectionChanged += Children_CollectionChanged;
        }
Example #2
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && !this.IsDisposed)
            {
                this.IsDisposed = true;

                if (this.Element != null)
                {
                    this.Element.Children.CollectionChanged -= this.Children_CollectionChanged;
                    this.Element.NextRequired  -= this.Element_NextRequired;
                    this.Element.IndexRequired -= this.Element_IndexRequired;
                }

                if (this.VP != null)
                {
                    this.VP.RemoveFromParent();
                    this.VP.Dispose();
                    this.VP = null;
                }

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

                if (this.PointsContainer != null)
                {
                    this.PointsContainer.RemoveFromParent();
                    this.PointsContainer.Dispose();
                    this.PointsContainer = null;
                }

                // Root 做为 Control ,应该由 base 释放
                //if (this.Root != null) {
                //    this.Root.Dispose();
                //    this.Root = null;
                //}
            }

            base.Dispose(disposing);
        }