Esempio n. 1
0
        private void UpdateRecordBindingContext(int newRowIndex, GridRowPanel rowPanel, IList itemsSource, int oldRowIndex)
        {
            var record =
                (Children.FirstOrDefault(row =>
            {
                var gridRowPanel = row as GridRowPanel;
                return(gridRowPanel != null && gridRowPanel.RowIndex == oldRowIndex);
            }) as GridRowPanel);

            if (record == null)
            {
                return;
            }
            record.RowIndex = oldRowIndex != -1 ? newRowIndex : rowPanel.RowIndex;
            var i = 1;

            foreach (var recordChild in record.Children)
            {
                if (i > -1)
                {
                    recordChild.BindingContext = null;
                    recordChild.BindingContext = itemsSource[(newRowIndex * 2) - i];
                }
                --i;
            }
        }
Esempio n. 2
0
        private void UpdateAndCreateRow(int newRowIndex, int oldRowIndex)
        {
            var itemList    = DependencyService.Get <IDataView>().ItemsSource;
            var itemsSource = itemList as IList;

            if (oldRowIndex != -1)
            {
                var record = RowPanel.FirstOrDefault(row => (row as GridRowPanel).RowIndex == newRowIndex);
                UpdateRecordBindingContext(oldRowIndex, record as GridRowPanel, itemsSource, newRowIndex);
                return;
            }
            var rowPanel = new GridRowPanel();

            for (var rowIndexer = 0; rowIndexer < 2; rowIndexer++)
            {
                if (rowPanel == null)
                {
                    rowPanel = new GridRowPanel();
                }
                var columnIndex = rowIndexer % 2;
                rowPanel.VisibleRowIndex = newRowIndex;
                var cellPanel = new GridCellPanel {
                    ColIndex = columnIndex
                };
                var view = GenerateViewFromTemplate(itemsSource[(newRowIndex * 2) - rowIndexer]);
                cellPanel.BindingContext = itemsSource[(newRowIndex * 2) - rowIndexer];
                cellPanel.Children.Add(view);
                rowPanel.Children.Add(cellPanel);
                if (columnIndex < 1)
                {
                    continue;
                }
                rowPanel.RowIndex = ++newRowIndex;
                if (Children.All(row =>
                {
                    var gridRowPanel = row as GridRowPanel;
                    return(gridRowPanel != null && gridRowPanel.RowIndex != rowPanel.RowIndex);
                }))
                {
                    if (Children.Any(row =>
                    {
                        var gridRowPanel = row as GridRowPanel;
                        return(gridRowPanel != null && gridRowPanel.RowIndex == -1);
                    }))
                    {
                        UpdateRecordBindingContext(newRowIndex - 1, rowPanel, itemsSource, oldRowIndex);
                    }
                    else
                    {
                        Children.Add(rowPanel.Clone());
                        Debug.WriteLine("New Child added at row {0}", rowPanel.RowIndex);
                        RowPanel = Children;
                        ForceLayout();
                    }
                }
                rowPanel = null;
            }
        }
Esempio n. 3
0
        internal void GenerateRows()
        {
            if (Children.Count > 0)
            {
                Debug.WriteLine("ReMeasured");
                return;
            }
            var itemList    = DependencyService.Get <IDataView>().ItemsSource;
            var itemsSource = itemList as IList;

            if (itemsSource != null && itemsSource.Count <= 0)
            {
                return;
            }
            rowCount = Math.Round(viewPortHeight / SGridView.GridSize.RowHeight) * 2;
            var rowPanel = new GridRowPanel();

            for (var rowIndexer = 0; rowIndexer < rowCount; rowIndexer++)
            {
                if (rowPanel == null)
                {
                    rowPanel = new GridRowPanel();
                }
                var columnIndex = rowIndexer % 2;
                var rowIndex    = (int)Math.Floor(rowIndexer / (float)2);
                var cellPanel   = new GridCellPanel {
                    ColIndex = columnIndex
                };
                var view = GenerateViewFromTemplate(itemsSource[rowIndexer]);
                cellPanel.BindingContext = itemsSource[rowIndexer];
                cellPanel.Children.Add(view);
                rowPanel.Children.Add(cellPanel);
                rowPanel.VisibleRowIndex = rowIndex;
                rowPanel.RowIndex        = ++rowIndex;
                if (columnIndex < 1)
                {
                    continue;
                }
                Children.Add(rowPanel.Clone());
                rowPanel = null;
            }
            ForceLayout();
        }