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

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

问题描述

我正在尝试设置/获取 RichTextBox 的文本,但是当我想要获取 test.Text 时,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 framework 3.5 SP1) 中使用了代码

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

RichTextBox test = new RichTextBox();

不能有 test.Text(?)

你知道怎么可能吗?

推荐答案

设置 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) 没有字符串属性“Text";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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