简体   繁体   English

无法清除文本框和RichTextBox

[英]Cant clear textbox and richtextbox

I have a WPF project with a navigation window and a few pages. 我有一个带有导航窗口和几页的WPF项目。 On one page I have a textbox and two richtextboxes. 在一页上,我有一个文本框和两个richtextbox。 With a click on a button I want to clear the textbox and the two richtextboxes with the following code: 通过单击按钮,我想使用以下代码清除文本框和两个Richtextbox:

private void resetGUI()
{
    txtIndex.Clear();
    richEinzelTxtBemerkung.Document.Blocks.Clear();
    richTxtBemerkung.Document.Blocks.Clear();
    checkHauptzeichnung.IsChecked = false;
}

But it doesnt work. 但它不起作用。 It seems that the clear method delete the value of the fields internal but in the GUI the value stays. 似乎clear方法删除了内部字段的值,但在GUI中该值保持不变。

So what do you think might cause this problem? 那么您认为什么可能导致此问题?

you can do 你可以做

txtIndex.Text = String.Empty;

or 要么

txtIndex.Text = "";

Okey i found my mistake. 奥基,我发现了我的错误。 I fill the Boxes again after clearing them. 清除它们后,我会再次填写框。 J found a mistake with a index count. J发现索引计数错误。

There is many way to clear Text of Rich Textbox. 有很多方法可以清除Rich TextBox的文本。

1) richTextbox.Text=""; 1) richTextbox.Text="";

2) richTextbox.Text=string.Empty; 2) richTextbox.Text=string.Empty;

3) Declare one global variable like: 3)声明一个全局变量,例如:

string emptyString=""; 字符串emptyString =“”;

and assign to every taxtbox, richtextbox and variable which you want to clear 并分配给您要清除的每个taxtbox,richtextbox和变量

a) richTextbox.Text=emptyString; a) richTextbox.Text=emptyString; b) nameTextbox.Text=emptyString; b) nameTextbox.Text=emptyString; c) name=emptyString; c) name=emptyString;

Thanks. 谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM