WP8:RichTextBox 没有 Document 属性 [英] WP8: RichTextBox has no Document property
问题描述
所以我在我的 WP8 项目的 xaml 页面上有一个 RichTextBox,设置如下:
So I have a RichTextBox on my xaml page in my WP8 project, set up like this:
<RichTextBox x:Name="ContentDisplay" IsReadOnly="True">
</RichTextBox>
我试图让它显示一些文本.我在网上找到的每一段代码都引用了 Document 属性.但是,当我尝试用它做任何事情时,它就是不存在.没有
I'm trying to get it to display some text. Every single piece of code I find on the net references Document property. However, when I try to do anything with it, it just isn't there. There's no
var test = ContentDisplay.Document;
设置为.
当我尝试使用上述行编译项目时,出现以下错误:
When I try to compile the project with aforementioned line, I get a following error:
'System.Windows.Controls.RichTextBox' does not contain a definition for 'Document'
and no extension method 'Document' accepting a first argument of type 'System.Windows.Controls.RichTextBox' could be found
(are you missing a using directive or an assembly reference?)
试图用谷歌搜索它,我发现引用了一个类似但不一样的问题,这一次人们试图使用文本"属性(与文档属性不同,它甚至不存在)那么,请告诉我如何使用该控件?
Trying to google it, i find references to a similar but-not-the-same problem, this time with people trying to use 'Text' property (which, unlike Document property, doesn't even exist) So, please tell, how can I use that control?
推荐答案
您可以使用 Blocks
和 Paragraphs
向该控件添加内容.下面将向 RichTextBlox
添加另一行.
You add content to this control using Blocks
and Paragraphs
. The following will add another line to the RichTextBlox
.
var paragraph = new Paragraph();
paragraph.Inlines.Add("Hello");
richText.Blocks.Add(paragraph);
<RichTextBox x:Name="richText">
<Paragraph>
<Run Text="Line one" />
</Paragraph>
</RichTextBox>
文档属性在控件的 Silverlight 版本上可用.不幸的是,并非所有功能都移植到 Windows 手机.
The Document property is available on the Silverlight version of the control. Unfortunately, not all features were ported to windows phone.
这篇关于WP8:RichTextBox 没有 Document 属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!