【问题标题】:WP8: RichTextBox has no Document propertyWP8:RichTextBox 没有 Document 属性
【发布时间】:2013-07-10 16:23:37
【问题描述】:

所以我的 WP8 项目的 xaml 页面上有一个 RichTextBox,设置如下:

<RichTextBox x:Name="ContentDisplay" IsReadOnly="True">

</RichTextBox>

我正试图让它显示一些文本。我在网上找到的每一段代码都引用了 Document 属性。但是,当我尝试用它做任何事情时,它就不存在了。没有

var test = ContentDisplay.Document;

设置为。

当我尝试使用上述行编译项目时,出现以下错误:

'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?)   

试图用谷歌搜索它,我发现了一个类似但不一样的问题的引用,这次是人们试图使用“文本”属性(与 Document 属性不同,它甚至不存在) 那么,请告诉我如何使用该控件?

【问题讨论】:

    标签: wpf xaml windows-phone-8 richtextbox


    【解决方案1】:

    您可以使用BlocksParagraphs 向此控件添加内容。以下将在RichTextBlox 中添加另一行。

    var paragraph = new Paragraph();
    paragraph.Inlines.Add("Hello");
    richText.Blocks.Add(paragraph);
    
    <RichTextBox x:Name="richText">
      <Paragraph>
        <Run Text="Line one" />
      </Paragraph>
    </RichTextBox>
    

    Document 属性在 Silverlight 版本的控件上可用。遗憾的是,并非所有功能都移植到了 windows phone。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-09-23
      • 2022-12-21
      • 2017-08-03
      • 2010-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-09
      相关资源
      最近更新 更多