如何将XAML插入RichTextBox?数据库中存储的XAML文本,XmlReader读取XAML后如何在RichTextBox中显示其文本?StringReaderstringReader=newStringReader(xamlString);XmlReaderxmlReader=XmlReader.Create(stringReader);rt.Document=???——更新————————这里是xamlString的内容:HelloHello1TestingTesting2从RichTextBox中检索XAML文本:privatestaticstringGetRTF(RichTextBoxrt){TextRangerange=newTextRange(rt.Document.ContentStart,rt.Document.内容结束);MemoryStream流=新的MemoryStream();范围。保存(流,DataFormats.Xaml);字符串xamlText=Encoding.UTF8.GetString(stream.ToArray());返回xamlText;}将XAML文本呈现为RichTextBox:privatestaticFlowDocumentSetRTF(stringxamlString){StringReaderstringReader=newStringReader(xamlString);XmlReaderxmlReader=XmlReader.Create(stringReader);Sectionsec=XamlReader.Load(xmlReader)作为Section;FlowDocumentdoc=newFlowDocument();while(sec.Blocks.Count>0)doc.Blocks.Add(sec.Blocks.FirstBlock);返回文档;}可以调用RichTextBox.AppendText(string)以上是C#学习教程:HowtoinsertXAMLintoRichTextBox?如果所有分享的内容对你有用,需要进一步了解C#学习教程,希望大家多多关注。本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
