2017-01-07 1 views
0

두 문자열 (RTF)이 있는데, 어떻게 든 병합해야합니다. - 두 줄 사이에 새 줄을 삽입하면 RichEditBox에 UWP로 표시됩니다. 두 개의 병합 RichTextBox 컨트롤을 사용하여 두 병합을 수행하는 해결 방법을 읽었지만 UWP에서는 실제로 옵션이 아니며 두 개의 RTE를 두 개의 RichEditBox 컨트롤에 표시 할 수도 없습니다. 타사 라이브러리를 사용하지 않고 다른 방법이 있습니까?UWP에서 두 개의 RTF 병합

답변

1

RichEditBox class을 사용하는 동안 ITextDocument interfaceITextRange interface을 활용하여 두 개의 RTF를 병합 할 수 있습니다. 다음은 간단한 예제입니다

var rtf1 = @"{\rtf1{\fonttbl{\f0 Verdana;}{\f1 Arial;}{\f2 Verdana;}{\f3 Calibri;}}{\colortbl;\red255\green255\blue255;\red255\green0\blue0;}\f0\cf2 This is red text marked by Verdana font.\par}"; 

// Sets rtf1 as the content of the document 
editor.Document.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, rtf1); 

// Get a new text range for the active story of the document. 
var range = editor.Document.GetRange(0, rtf1.Length); 

// Collapses the text range into a degenerate point at the end of the range for inserting. 
range.Collapse(false); 

var rtf2 = @"{\rtf1{\fonttbl{\f0 Times New Roman;}}{\colortbl;\red255\green255\blue255;\red0\green0\blue255;}\f0\cf2 This is blue text marked by Times New Roman font.\par}"; 

// Inserts rtf2 
range.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, rtf2); 

//var newrtf = string.Empty; 
//editor.Document.GetText(Windows.UI.Text.TextGetOptions.FormatRtf, out newrtf); 

//System.Diagnostics.Debug.WriteLine(newrtf); 

이 뜻 rtf1의 끝에 rtf2를 병합하고 자동으로 유효한 새 RTF를 생성합니다. ITextDocument.GetText method으로 새 RTF를 검색 할 수 있습니다.