크리에이티브 커먼즈 라이선스
Creative Commons License

Retrive a XAML text from RichTextBox:

private static string GetRTF(RichTextBox rt)
{
   
TextRange range = new TextRange(rt.Document.ContentStart, rt.Document.ContentEnd);
   
MemoryStream stream = new MemoryStream();
    range
.Save(stream, DataFormats.Xaml);
   
string xamlText = Encoding.UTF8.GetString(stream.ToArray());
   
return xamlText;
}

Render a XAML text into a RichTextBox:

private static FlowDocument SetRTF(string xamlString)
{
   
StringReader stringReader = new StringReader(xamlString);
   
XmlReader xmlReader = XmlReader.Create(stringReader);
   
Section sec = XamlReader.Load(xmlReader) as Section;
   
FlowDocument doc = new FlowDocument();
   
while (sec.Blocks.Count > 0)
        doc
.Blocks.Add(sec.Blocks.FirstBlock);
   
return doc;
}


저작자 표시
신고

'Study > WPF' 카테고리의 다른 글

[WPF_Program: Window Desktop Interface]  (3) 2011.02.12
[WPF: insert XAML into RichTextBox]  (0) 2010.12.20
[WPF: Diagramming. Saving you canvas to image]  (0) 2010.10.20
[WPF : Data Binding]  (0) 2010.07.28
Trackback 0 | Comment 0

강군v's Blog is powered by Daum & tistory

 

티스토리 툴바