检查多行文本框是否为空?

时间:2011-08-05 03:31:46

标签: c# wpf textbox string

我目前有以下XAML:

<TextBox Text="" x:Name="textFeedbackFeedback"
         Margin="11.593,0,29.307,42.96" TextWrapping="Wrap"
         VerticalContentAlignment="Top" VerticalAlignment="Bottom"
         Height="92.08" AcceptsReturn="True" VerticalScrollBarVisibility="Visible"/>

我尝试过使用很多变体:

if(textFeedbackFeedback.text == "")

if(textFeedbackFeedback.text == null)

if(textFeedbackFeedback.text == string.Empty)

if(string.IsNullOrEmpty(textFeedbackFeedback.Text))

但由于某种原因,它并没有就此止步并继续,好像那里有数据,有人可以帮助我。

感谢。

2 个答案:

答案 0 :(得分:5)

尝试if(string.IsNullOrWhiteSpace(textFeedbackFeedback.Text))

如果不起作用,请尝试找出文本的长度,以及文本中字符的整数/ ascii值。

答案 1 :(得分:0)

您可以尝试在文本上使用.Trim()函数来消除可能存在的任何空白区域。