// Creates a new cell copying all its properties from a currentRow. // RowSpan property is not copied; it's set to default value of 1. // The new cell as added to a newRow (at the endPosition of its Cells collection). private static TableCell AddCellCopy(TableRow newRow, TableCell currentCell, int cellInsertionIndex, bool copyRowSpan, bool copyColumnSpan) { Invariant.Assert(currentCell != null, "null check: currentCell"); TableCell newCell = new TableCell(); // Add the cell to a newRow's cell collection // It's good to do it here before inserting inline formatting elements // to avoid unnecessary TextContainer creation and content copying. if (cellInsertionIndex < 0) { newRow.Cells.Add(newCell); } else { newRow.Cells.Insert(cellInsertionIndex, newCell); } // Copy all properties LocalValueEnumerator properties = currentCell.GetLocalValueEnumerator(); while (properties.MoveNext()) { LocalValueEntry propertyEntry = properties.Current; if (propertyEntry.Property == TableCell.RowSpanProperty && !copyRowSpan || propertyEntry.Property == TableCell.ColumnSpanProperty && !copyColumnSpan) { // Skipping table structuring properties when requested continue; } // Copy a property if it is not ReadOnly if (!propertyEntry.Property.ReadOnly) { newCell.SetValue(propertyEntry.Property, propertyEntry.Value); } } // Copy a paragraph for a cell if (currentCell.Blocks.FirstBlock != null) { Paragraph newParagraph = new Paragraph(); // Transfer all known formatting properties that a locally set on a sourceBlock Paragraph sourceParagraph = currentCell.Blocks.FirstBlock as Paragraph; if (sourceParagraph != null) { DependencyProperty[] inheritableProperties = TextSchema.GetInheritableProperties(typeof(Paragraph)); DependencyProperty[] nonInheritableProperties = TextSchema.GetNoninheritableProperties(typeof(Paragraph)); for (int i = 0; i < nonInheritableProperties.Length; i++) { DependencyProperty property = nonInheritableProperties[i]; object value = sourceParagraph.ReadLocalValue(property); if (value != DependencyProperty.UnsetValue) { newParagraph.SetValue(property, value); } } for (int i = 0; i < inheritableProperties.Length; i++) { DependencyProperty property = inheritableProperties[i]; object value = sourceParagraph.ReadLocalValue(property); if (value != DependencyProperty.UnsetValue) { newParagraph.SetValue(property, value); } } } // Add paragraph to a cell newCell.Blocks.Add(newParagraph); } return newCell; }