Пример #1
0
 /// <summary>
 /// Inserts the display control for the specified cell.
 /// </summary>
 /// <param name="cellRef">The cell reference.</param>
 private void InsertDisplayControl(CellRef cellRef)
 {
     var e = this.CreateDisplayControl(cellRef, null, null);
     SetElementPosition(e, cellRef);
     this.sheetGrid.Children.Insert(this.cellInsertionIndex, e);
     this.cellInsertionIndex++;
     this.cellMap.Add(cellRef.GetHashCode(), e);
 }
Пример #2
0
 /// <summary>
 /// Gets the element at the specified cell.
 /// </summary>
 /// <param name="cellRef">The cell reference.</param>
 /// <returns>
 /// The element, or <c>null</c> if the cell was not found.
 /// </returns>
 public UIElement GetCellElement(CellRef cellRef)
 {
     UIElement e;
     return this.cellMap.TryGetValue(cellRef.GetHashCode(), out e) ? e : null;
 }
Пример #3
0
        /// <summary>
        /// Adds the display control for the specified cell.
        /// </summary>
        /// <param name="cellRef">The cell reference.</param>
        private void AddDisplayControl(CellRef cellRef)
        {
            var e = this.CreateDisplayControl(cellRef, null, null);
            if (e == null)
            {
                return;
            }

            SetElementPosition(e, cellRef);
            this.sheetGrid.Children.Add(e);
            this.cellMap.Add(cellRef.GetHashCode(), e);
        }
Пример #4
0
        /// <summary>
        /// Updates the content of the specified cell.
        /// </summary>
        /// <param name="cellRef">The cell reference.</param>
        protected void UpdateCellContent(CellRef cellRef)
        {
            var c = this.GetCellElement(cellRef);
            if (c != null)
            {
                this.sheetGrid.Children.Remove(c);
                this.cellInsertionIndex--;
                this.cellMap.Remove(cellRef.GetHashCode());
            }

            this.InsertDisplayControl(cellRef);
        }
Пример #5
0
        /// <summary>
        /// The insert cell element.
        /// </summary>
        /// <param name="cellRef">
        /// The cell ref.
        /// </param>
        /// <param name="value">
        /// The value.
        /// </param>
        /// <param name="insert">
        /// The insert.
        /// </param>
        private void InsertCellElement(CellRef cellRef, object value, bool insert)
        {
            // if (value == null)
            // return;
            var e = this.CreateElement(cellRef, null);
            SetElementPosition(e, cellRef);
            if (insert)
            {
                this.sheetGrid.Children.Insert(this.cellInsertionIndex, e);
                this.cellInsertionIndex++;
            }
            else
            {
                this.sheetGrid.Children.Add(e);
            }

            this.cellMap.Add(cellRef.GetHashCode(), e);
        }
Пример #6
0
        /// <summary>
        /// Virtualizes the UIElements for the visible cells.
        ///   Adds elements for the visible cells not currently in the logical tree.
        ///   Removes elements for the nonvisible cells.
        /// </summary>
        protected void VirtualizeCells()
        {
            CellRef cell1, cell2;
            this.GetVisibleCells(out cell1, out cell2);
            if (cell1.Column < 0)
            {
                return;
            }

            var delete = this.cellMap.Keys.ToList();

            for (int i = cell1.Row; i <= cell2.Row; i++)
            {
                for (int j = cell1.Column; j <= cell2.Column; j++)
                {
                    var cellRef = new CellRef(i, j);
                    var c = this.GetCellElement(cellRef);
                    if (c == null)
                    {
                        // The cell is not currently in the collection - add it
                        this.UpdateCellContent(cellRef);
                    }
                    else
                    {
                        // the cell is currently in the collection - keep it (remove it from the delete keys)
                        delete.Remove(cellRef.GetHashCode());
                    }
                }
            }

            foreach (var hash in delete)
            {
                var cell = this.cellMap[hash];
                this.sheetGrid.Children.Remove(cell);
                this.cellInsertionIndex--;
                this.cellMap.Remove(hash);
            }
        }
Пример #7
0
        protected void UpdateCellContent(CellRef cellRef)
        {
            var c = GetCellElement(cellRef);
            var value = GetCellValue(cellRef);

            if (c != null)
            {
                sheetGrid.Children.Remove(c);
                cellInsertionIndex--;
                cellMap.Remove(cellRef.GetHashCode());
            }
            InsertCellElement(cellRef, value, true);
        }