【发布时间】:2017-04-21 09:11:42
【问题描述】:
所以在 WPF 中我创建了一个 RichTextBox 并实现了能够格式化所选文本(粗体、未划线、字体等)的功能,但现在我想将所有格式导出到 XML文件,所以当我加载它时,加载的文件会给我相同格式的相同文本。 我认为最好的方法是,如果我能在 RTB 中找到每个有格式的地方,然后将其保存为文本范围,但我不知道 RTB 是否有方法来查找文本的一部分已格式化。
这是我所拥有的: xml:
<Button Name = "export" Click = "export_Click"/>
<RichTextBox x:Name="RTB"/>
和c#:
private void export_Click(object sender, RoutedEventArgs e){
TextRange range = new TextRange();
//here is where i want to access the formatted areas
//something like: range = RTB.document.getBoldArea();
//and then i could export what i got in the text range to a xml file
}
提前感谢任何愿意提供帮助的人!
【问题讨论】:
标签: c# xml wpf formatting richtextbox