0
A
답변
1
원본 실행을 대상 실행으로 복제 한 다음 대상 실행의 텍스트를 변경할 수 있습니다.
// Create a formatted source run
Run sourceRun = new Run("TextOfSourceRun") { FontWeight = FontWeights.Bold, Background = Brushes.Khaki, Foreground = Brushes.Green, FontSize = 25 };
// Clone it
Run targetRun = ElementClone<Run>(sourceRun);
// Change the text of the target run
targetRun.Text = "TextOfTargetRun";
// Insert the target run at the end of the current paragraph
richTextBox.CaretPosition.Paragraph.Inlines.InsertAfter(richTextBox.CaretPosition.Paragraph.Inlines.Last(), targetRun);
public static T ElementClone<T>(T element)
{
object clonedElement = null;
MemoryStream memStream = new MemoryStream();
XamlWriter.Save(element, memStream);
if (memStream.CanRead)
{
memStream.Seek(0, SeekOrigin.Begin);
clonedElement = XamlReader.Load(memStream);
memStream.Close();
}
return (T)clonedElement;
}