■ FlowDocument 클래스를 사용해 첫번째 RUN 객체를 찾는 방법을 보여준다.
▶ FlowDocument 클래스 : 첫번째 RUN 찾기 예제 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
using System; using System.Windows.Documents; FlowDocument flowDocument; ... TextPointer startPointer = flowDocument.ContentStart; TextPointer textPointer = FindFirstRun(startPointer); if(textPointer != null) { string text = textPointer.GetTextInRun(LogicalDirection.Forward); Console.WriteLine(text); } |
▶ FlowDocument 클래스 : 첫번째 RUN 찾기 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using System.Windows.Controls; #region 첫번째 RUN 찾기 - FindFirstRun(startPointer) /// <summary> /// 첫번째 RUN 찾기 /// </summary> /// <param name="startPointer">시작 포인터</param> /// <returns>첫번째 RUN 포인터</returns> public TextPointer FindFirstRun(TextPointer startPointer) { TextPointer textPointer = startPointer; while(textPointer != null) { if(textPointer.GetPointerContext(LogicalDirection.Backward) == TextPointerContext.ElementStart) { if(textPointer.Parent is Run) { break; } } textPointer = textPointer.GetNextContextPosition(LogicalDirection.Forward); } return textPointer; } #endregion |