如何将富文本文档内联转换回标签 [英] How to convert richtext document inlines back to Label
本文介绍了如何将富文本文档内联转换回标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 WPF 富文本框自定义控件.并通过
I have a WPF richtextbox custom control. And have added different inlines to Richtextbox paragraph by
Label curToken = new Label() { Content = curTokenText };
new InlineUIContainer(curToken, insertHere);
tokenList.Add(curToken);
现在我想检索所有内联元素并将它们转换回 UIElement(在本例中为 Label).连同所有内联文本.我怎样才能做到这一点.
Now i want to retrieve all the inline elements and convert them back to UIElement (Label in this case). Along with all the inline text. How can i achieve that.
推荐答案
您可以像下面这样迭代内联以取回标签:
You can iterate over inlines like below to get back the labels:
List<UIElement> labels = new List<UIElement>();
foreach (var block in myRTB.Document.Blocks)
{
if (block is Paragraph)
{
var paragraph = block as Paragraph;
foreach (var inline in paragraph.Inlines)
{
if(inline is InlineUIContainer)
{
labels.Add(((InlineUIContainer)inline).Child);
}
}
}
}
这篇关于如何将富文本文档内联转换回标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文