如何从 Silverlight 4 RichTextBox 控件加载和保存内容?
我一直在审查 Silverlight 4 中 RichTextBox 控件的功能。
我还没有找到在 RichTextBox 中加载和保存内容的任何示例。
有人遇到过或者可以解释一下吗?
该控件有一个 BlocksCollection,我猜想可以使用 XamlReader 来加载一堆标记,假设标记有一个类型为 Block 的顶级节点。然后将该块添加到 Blocks 集合中。在这种情况下,RichTextBox 费心去拥有一个“集合”,这似乎很遗憾,为什么不简单地使用一个顶级 Block
项呢?
尽管如此,仍然需要保存 RichTextBox 的内容,我不知道从哪里开始?
我确信我一定错过了这里明显的内容,但除非从 RichTextBox 加载和保存数据至少是可能的(如果不容易),否则我看不到我们如何实际使用它。
编辑
感谢DaveB的回答,我发现了有关DocumentPersister
的讨论。但是,在 MSDN 文档中找不到对该类的引用,也无法通过对象浏览器搜索在已安装的 dll 中找到它。任何人,任何人吗?
I've been reviewing the features of the RichTextBox control in Silverlight 4.
What I've yet to find is any examples of Loading and Saving content in the RichTextBox.
Anyone come across any or can shed some light on it?
The control has a BlocksCollection in which I guess one could use the XamlReader
to load a bunch of markup assuming that markup has a single top level node of type Block
. Then add that block to the Blocks collection. Seems a shame that the RichTextBox bothers to have a "collection" in this case, why not simply a top-level Block
item?
Never-the-less that still leaves saving the content of a RichTextBox, I have no idea where to begin with that one?
I'm sure I must be missing the obvious here but unless loading and saving data in to and from RichTextBox is at least possible if not easy I can't see how we can actually put it to use.
Edit
Thanks to DaveB's answer I found discussion of something called the DocumentPersister
. However no reference to this class can be found in the MSDN documentation nor can I find it in the installed dlls via object browser search. Anyone, anyone at all?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
查看此教程
在 RichTextArea 控件上。练习 2 的任务 3 中描述了持久内容。本教程的代码包括一个帮助程序类。
编辑:
提出了有关教程中引用的
DocumentPersister
类的问题。它可以在本教程的源代码下载中找到。我认为作者创造了它。通过查看代码,您将了解如何保存数据。唯一的缺点是,如果您的数据包含图像,则辅助类不支持它们。这是下载链接。http://ecn.channel9.msdn.com/ o9/learn/Silverlight4/Labs/TextEditor/Source.zip
Check out this tutorial
on the RichTextArea control. Persisting content is described in exercise 2, task 3. The code for the tutorial includes a helper class.
Edit:
The question was raised about the
DocumentPersister
class referenced in the tutorial. It is found in the source code download for the tutorial. I think the author created it. By looking at the code you will get an idea as to persisting your data. The only downside was that if your data contained images, the helper class did not support them. Here is the link to the download.http://ecn.channel9.msdn.com/o9/learn/Silverlight4/Labs/TextEditor/Source.zip
只是为了更新已接受答案中的链接,它已移至此处:
http://channel9.msdn.com/learn/courses/Silverlight4 /NewFeatures/RichTextBox/简介/
Just to update the link in the accepted answer, it's moved to here:
http://channel9.msdn.com/learn/courses/Silverlight4/NewFeatures/RichTextBox/Introduction/
在确认 Silverlight 4 RichTextArea 将支持完整的 RichEdit 功能(如项目符号/列表等)之前,请小心不要在 Silverlight 4 RichTextArea 上投入过多,而目前它在 SL Beta 1 中已经实现了...尽管我确信它会在 RTM 中实现?
Be wary of investing too much in the Silverlight 4 RichTextArea until it's confirmed that it will support full RichEdit functionality like bullet points/lists etc which it currently does in SL Beta 1... although I'm sure it will in RTM?
我有一个来自 Microsoft 的示例来保存我必须找到的内容,我明天将做这些内容。我在 10 月份得到了这个示例,当时 beta 4 甚至还没有发布,因此没有可用的教程。自从那个项目以来,我还没有从事过 silverlight 工作,所以我不知道现在有多少教程可用。
好的,我已经找到了。我应该在哪里上传?
I have a sample from Microsoft to persist the contents which I have to find which I will do tomorrow. I got this sample in october when beta 4 was not even announces due to which there were no tutorials available. Since that project I have not worked on silverlight so I don't know how many tutorials are available now.
ok I have found it. Where should I upload it?
将文本加载到 RichTextBox 的一种选择是使用 XamlReader。根据您计划加载的文本,您可能需要在其周围添加标签
One option for loading text into RichTextBox is to use XamlReader. Dependent on the text which you are planning to load, you might need to add tag around it