public override View GetView(int position, View reusableView, ViewGroup parent)
            {
                UIElement listItem = null;
                if (reusableView == null)
                {
                    reusableView = new WrapedViewGroup(parent.Context);
                    listItem = ((UIElement)this.Generator.Generate(position));
                    LogicalTreeHelper.AddLogicalChild(this.VirtualizingStackPanel, listItem);
                    this.NativeViewContainers.Add(listItem.NativeUIElement, listItem);
                    ((WrapedViewGroup)reusableView).AddView(listItem.NativeUIElement);
                }
                else
                {

                    var nativeItem = ((WrapedViewGroup)reusableView).GetChildAt(0);
                    if (this.NativeViewContainers.ContainsKey(nativeItem))
                    {
                        listItem = this.NativeViewContainers[nativeItem];
                        this.Generator.Reuse(position, listItem);
                    }
                    else
                    {
                        ((WrapedViewGroup)reusableView).RemoveAllViews();
                        listItem = ((UIElement)this.Generator.Generate(position));
                        LogicalTreeHelper.AddLogicalChild(this.VirtualizingStackPanel, listItem);
                        this.NativeViewContainers.Add(listItem.NativeUIElement, listItem);
                        ((WrapedViewGroup)reusableView).AddView(listItem.NativeUIElement);
                    }
                }

                var availableSize = this.VirtualizingStackPanel.Orientation == Orientation.Horizontal
                        ? new SizeF(float.PositiveInfinity, this.VirtualizingStackPanel.measuredSize.Height)
                        : new SizeF(this.VirtualizingStackPanel.measuredSize.Width, float.PositiveInfinity);
                var measuredSize = listItem.MeasureOverride(availableSize);
                listItem.Arrange(new RectangleF(PointF.Empty, measuredSize));

                // Need to use AbsListView.LayoutParams to prevent Java.CastException
                reusableView.LayoutParameters = new AbsListView.LayoutParams((int)ScreenProperties.ConvertDPIToPixels(listItem.measuredSize.Width), (int)ScreenProperties.ConvertDPIToPixels(listItem.measuredSize.Height));

                return reusableView;
            }
示例#2
0
            public override View GetView(int position, View reusableView, ViewGroup parent)
            {
                UIElement listItem = null;
                if (reusableView == null)
                {
                    reusableView = new WrapedViewGroup(parent.Context);
                    listItem = ((UIElement)this.Generator.Generate(position));
                    LogicalTreeHelper.AddLogicalChild(this.ListPicker, listItem);
                    this.NativeViewContainers.Add(listItem.NativeUIElement, listItem);
                    ((WrapedViewGroup)reusableView).AddView(listItem.NativeUIElement);
                }
                else
                {

                    var nativeItem = ((WrapedViewGroup)reusableView).GetChildAt(0);
                    if (this.NativeViewContainers.ContainsKey(nativeItem))
                    {
                        listItem = this.NativeViewContainers[nativeItem];
                        this.Generator.Reuse(position, listItem);
                    }
                    else
                    {
                        ((WrapedViewGroup)reusableView).RemoveAllViews();
                        listItem = ((UIElement)this.Generator.Generate(position));
                        LogicalTreeHelper.AddLogicalChild(this.ListPicker, listItem);
                        this.NativeViewContainers.Add(listItem.NativeUIElement, listItem);
                        ((WrapedViewGroup)reusableView).AddView(listItem.NativeUIElement);
                    }
                }
                var width = GetDialogWidth() / WidthDivider;
                var availableSize = new SizeF(ScreenProperties.ConvertPixelsToDPI(width), float.PositiveInfinity);
                var measuredSize = listItem.MeasureOverride(availableSize);
                listItem.Arrange(new RectangleF(PointF.Empty, measuredSize));
                ThreadPool.QueueUserWorkItem(o => DisableTouch((View)listItem.NativeUIElement.Parent));
                // Need to use AbsListView.LayoutParams to prevent Java.CastException
                reusableView.LayoutParameters = new AbsListView.LayoutParams((int)width, (int)ScreenProperties.ConvertDPIToPixels(listItem.measuredSize.Height));
                //if (position == this.SelectedItemPosition)
                //{
                //    listItem.NativeUIElement.SetBackgroundColor(Android.Graphics.Color.ParseColor("#33b5e5"));
                //    lastSelectedView = listItem.NativeUIElement;
                //}
                //else
                //{
                //    listItem.NativeUIElement.SetBackgroundColor(Android.Graphics.Color.Transparent);
                //}

                return reusableView;
            }