コード例 #1
0
        public override RecyclerView.ViewHolder OnCreateViewHolder(ViewGroup parent, int viewType)
        {
            //var gridViewCell = viewType == 0 ?
            //    Element.ItemTemplate.CreateContent() as JWChinese.GridViewCell :
            //    Element.GroupHeaderTemplate.CreateContent() as JWChinese.GridViewCell;
            var gridViewCell = viewType == 0 ?
                               Element.ItemTemplate.CreateContent() as ViewCell :
                               Element.GroupHeaderTemplate.CreateContent() as ViewCell;

            // reflection method of setting isplatformenabled property
            // We are going to re-set the Platform here because in some cases (headers mostly) its possible this is unset and
            // when the binding context gets updated the measure passes will all fail. By applying this here the Update call
            // further down will result in correct layouts.

            try
            {
                var p = PlatformProperty.GetValue(Element);
                PlatformProperty.SetValue(gridViewCell, p);
            }
            catch (Exception e) { }


            var initialCellSize = new Xamarin.Forms.Size(Element.MinItemWidth, Element.RowHeight);
            var view            = new GridViewCellContainer(parent.Context, gridViewCell, parent, initialCellSize);

            //Only add the click handler for items (not group headers.)
            if (viewType == 0)
            {
                view.Click += mMainView_Click;

                view.LongClickable = true;
            }

            //Height of the view will be taken as RowHeight for child items
            //and the heightrequest property of the first view in the template
            //or the render height (whatever that is) if the heightrequest property is not defined.
            var height = viewType == 0 ? Convert.ToInt32(Element.RowHeight) :
                         gridViewCell.View.HeightRequest != -1 ?
                         Convert.ToInt32(gridViewCell.View.HeightRequest) :
                         Convert.ToInt32(gridViewCell.RenderHeight);

            var width = Convert.ToInt32(Element.MinItemWidth);
            var dpW   = ConvertDpToPixels(width);
            var dpH   = ConvertDpToPixels(height);

            //If there are no minimums then the view doesn't render at all.
            view.SetMinimumWidth(dpW);
            view.SetMinimumHeight(dpH);

            var d = Resources.System.GetDrawable("statelist_item_background.xml");

            view.SetBackground(d);

            //If not set to match parent then the view doesn't stretch to fill.
            //This is not necessary anymore with the plaform fix above.
            //view.LayoutParameters = new GridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);

            //Wrap the view.
            GridViewCell myView = new GridViewCell(view);

            //return the view.
            return(myView);
        }
コード例 #2
0
 public GridViewCell(GridViewCellContainer view) : base(view)
 {
     ViewCellContainer = view;
 }