public override void ViewDidLoad()
        {
            this.AddOption ("Manual", LoadOnDemandManual, "Load on demand mode");
            this.AddOption ("Auto", LoadOnDemandAuto, "Load on demand mode");

            base.ViewDidLoad ();

            this.photos.LoadDataFromJSONResource ("PhotosWithNames", "json", "photos");
            this.names.LoadDataFromJSONResource ("PhotosWithNames", "json", "names");

            this.listViewDataSource = new ListViewDataSource (this);
            this.listViewDelegate = new ListViewDelegate (this);

            listView.Frame = this.View.Bounds;
            listView.BackgroundColor = new UIColor (0.0f, 1.0f, 0.0f, 0.5f);
            listView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
            listView.Delegate = this.listViewDelegate;
            listView.DataSource = this.listViewDataSource;
            listView.LoadOnDemandBufferSize = 5;
            listView.LoadOnDemandMode = TKListViewLoadOnDemandMode.Manual;
            listView.ContentInset = new UIEdgeInsets (10, 10, 10, 10);
            this.View.AddSubview (listView);
            listView.RegisterClassForCell(new ObjCRuntime.Class(typeof(CustomCardListViewCell)), "cell");

            TKListViewLinearLayout layout = (TKListViewLinearLayout)listView.Layout;
            layout.ItemSize = new CGSize (100, 120);
            layout.ItemSpacing = 5;
            layout.ItemAlignment = TKListViewItemAlignment.Stretch;
        }
示例#2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            dataSource.LoadDataFromJSONResource ("ListViewSampleData", "json", "teams");
            dataSource.GroupItemSourceKey = "items";
            dataSource.FilterWithQuery ("key like 'Marketing'");
            dataSource.GroupWithKey ("key");

            this.UpdateData (3);

            this.listViewDataSource =  new ListViewDataSource (this);
            this.listViewDelegate = new ListViewDelegate (this);

            TKListView listView = new TKListView (this.View.Bounds);
            listView.RegisterClassForCell (new ObjCRuntime.Class (typeof(TKListViewCell)), "cell");
            listView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            listView.DataSource = this.listViewDataSource;
            listView.Delegate = this.listViewDelegate;
            listView.AllowsPullToRefresh = true;
            listView.PullToRefreshTreshold = 70;
            listView.PullToRefreshView.BackgroundColor = UIColor.Blue;
            listView.PullToRefreshView.ActivityIndicator.Color = UIColor.White;
            this.View.AddSubview (listView);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            this.Photos = new TKDataSource ("PhotosWithNames", "json", "photos");
            this.Names = new TKDataSource ("PhotosWithNames", "json", "names");

            this.listViewDataSource = new ListViewDataSource (this);

            TKListView listView = new TKListView (this.View.Bounds);
            listView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            listView.DataSource = this.listViewDataSource;
            this.View.AddSubview (listView);
            listView.RegisterClassForCell (new Class(typeof(ImageWithTextListViewCell)), "cell");

            TKListViewGridLayout layout = new TKListViewGridLayout();
            layout.ItemAlignment = TKListViewItemAlignment.Center;
            layout.SpanCount = 2;
            layout.ItemSize = new CGSize (150, 200);
            layout.LineSpacing = 60;
            layout.ItemSpacing = 10;
            listView.Layout = layout;

            TKView view = new TKView ();
            view.Fill = TKLinearGradientFill.WithColors (new UIColor[] {
                new UIColor (0.35f, 0.68f, 0.89f, 0.89f),
                new UIColor (0.35f, 0.68f, 1.0f, 1.0f),
                new UIColor (0.85f, 0.8f, 0.2f, 0.8f)
            });
            listView.BackgroundView = view;
        }
        protected override void OnElementChanged(ElementChangedEventArgs <ListView> e)
        {
            _requestedScroll = null;

            if (e.OldElement != null)
            {
                var controller = (IListViewController)e.OldElement;
                var headerView = (VisualElement)controller.HeaderElement;
                if (headerView != null)
                {
                    headerView.MeasureInvalidated -= OnHeaderMeasureInvalidated;
                }

                var footerView = (VisualElement)controller.FooterElement;
                if (footerView != null)
                {
                    footerView.MeasureInvalidated -= OnFooterMeasureInvalidated;
                }

                e.OldElement.ScrollToRequested -= OnScrollToRequested;
                e.OldElement.TemplatedItems.CollectionChanged        -= OnCollectionChanged;
                e.OldElement.TemplatedItems.GroupedCollectionChanged -= OnGroupedCollectionChanged;
            }

            if (e.NewElement != null)
            {
                if (Control == null)
                {
                    _tableViewController = new FormsUITableViewController(e.NewElement);
                    SetNativeControl(_tableViewController.TableView);
                    if (Forms.IsiOS9OrNewer)
                    {
                        Control.CellLayoutMarginsFollowReadableWidth = false;
                    }

                    _insetTracker = new KeyboardInsetTracker(_tableViewController.TableView, () => Control.Window, insets => Control.ContentInset = Control.ScrollIndicatorInsets = insets, point =>
                    {
                        var offset = Control.ContentOffset;
                        offset.Y  += point.Y;
                        Control.SetContentOffset(offset, true);
                    });
                }
                _shouldEstimateRowHeight = true;
                //if the user specifies he wants to sacrifice performance we will do things like:
                // - don't EstimateRowHeight anymore
                if (e.NewElement.TakePerformanceHit)
                {
                    _shouldEstimateRowHeight = false;
                }

                e.NewElement.ScrollToRequested += OnScrollToRequested;
                e.NewElement.TemplatedItems.CollectionChanged        += OnCollectionChanged;
                e.NewElement.TemplatedItems.GroupedCollectionChanged += OnGroupedCollectionChanged;

                UpdateRowHeight();

                Control.Source = _dataSource = e.NewElement.HasUnevenRows ? new UnevenListViewDataSource(e.NewElement, _tableViewController) : new ListViewDataSource(e.NewElement, _tableViewController);

                UpdateEstimatedRowHeight();
                UpdateHeader();
                UpdateFooter();
                UpdatePullToRefreshEnabled();
                UpdateIsRefreshing();
                UpdateSeparatorColor();
                UpdateSeparatorVisibility();

                var selected = e.NewElement.SelectedItem;
                if (selected != null)
                {
                    _dataSource.OnItemSelected(null, new SelectedItemChangedEventArgs(selected));
                }
            }

            base.OnElementChanged(e);
        }
示例#5
0
 public UnevenListViewDataSource(ListViewDataSource source) : base(source)
 {
 }