RichTextBox的(WPF)没有字符串属性"文本" [英] RichTextBox (WPF) does not have string property "Text"

查看:244
本文介绍了RichTextBox的(WPF)没有字符串属性"文本"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置/获取我RichTextBox中的文本,但文本不是它的属性列表中,当我想要得到test.Text ...

I am trying to set/get the text of my RichTextBox, but Text is not among list of its properties when I want to get test.Text...

我在C#(.NET框架3.5 SP1)

I am using code behind in C# (.net framework 3.5 SP1)

RichTextBox test = new RichTextBox();

不能 test.Text(?)

你知道怎么来的也可以是可能的吗?

Do you know how come it can be possible ?

推荐答案

设置 RichTextBox的文本:

to set RichTextBox text:

richTextBox1.Document.Blocks.Clear();
richTextBox1.Document.Blocks.Add(new Paragraph(new Run("Text")));

获得 RichTextBox的文本:

to get RichTextBox text:

string richText = new TextRange(richTextBox1.Document.ContentStart, richTextBox1.Document.ContentEnd).Text;

这篇关于RichTextBox的(WPF)没有字符串属性"文本"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆