/// <summary> /// Recycle the specified newItem, cells and position. /// </summary> /// <param name="newItem">New item.</param> /// <param name="cells">Cells.</param> /// <param name="position">Position.</param> public void Recycle(TetrixViewModelBase newItem, IList <TetrixViewModelBase> cells, int position, bool recalculatePositions = true) { // TODO: linear search yuck, lets add a binary search here for fast insertion bool found = false; newItem.Position = position; foreach (var cell in cells) { if (cell.CellId.Equals(newItem.CellId)) { cell.Apply(newItem); found = true; break; } } if (!found) { // reset event handler for cell selected //newItem.Selected -= CellSelected; //newItem.Selected += CellSelected; if (position <= cells.Count - 1 && position >= 0) { cells.Insert(position, newItem); } else { cells.Add(newItem); } } if (recalculatePositions) { RecalculatePositions(cells); } }
/// <summary> /// Apply this instance. /// </summary> public virtual void Apply(TetrixViewModelBase newItem) { }