wpf 在 RichTextBox 中设置文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12726460/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 05:38:56  来源:igfitidea点击:

Setting text in a RichTextBox

c#wpfrichtextbox

提问by IMX

Possible Duplicate:
RichTextBox (WPF) does not have string property “Text”

可能重复:
RichTextBox (WPF) 没有字符串属性“Text”

This is ridiculous, my RichTextBox has no document or paragraph property. How am I supposed to add text to it via C#?

这太荒谬了,我的 RichTextBox 没有文档或段落属性。我应该如何通过 C# 向它添加文本?

<ScrollViewer Margin="16,56,16,16">
                <RichTextBox x:Name="PREVIEWTEMP"
                             HorizontalContentAlignment="Stretch"
                             VerticalContentAlignment="Top"
                             Padding="0,6,0,0"
                             Height="528"
                             Width="400"
                             IsReadOnly="True">
                    <Paragraph>
                        <Run Text="RichTextBox" />
                    </Paragraph>
                </RichTextBox>
            </ScrollViewer>

Does anyone know how to do this?

有谁知道如何做到这一点?

回答by Jay

Paragraph needs to sit inside a element.

段落需要位于元素内。

Take a look at this site, it has some good examples http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-richtextbox/

看看这个站点,它有一些很好的例子http://www.c-sharpcorner.com/UploadFile/mahesh/wpf-richtextbox/

回答by Florian Gl

You could create a RichTextViewer which inherits from RichTextBox as showed here(post by e-rock).

你可以从你的RichTextBox创建它继承了RichTextViewer作为显示在这里(后通过e-岩石)。