2011-08-05 166 views
0

我现在有以下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)) 

但由于某些原因,它不会停在那里,并继续仿佛有数据在那里,有人可以帮我在这里。

谢谢。

+0

你确定它是空的吗?那里没有回车?那如何String.IsNullOrWhiteSpace(textBox.Text)? –

+0

请勿在标题中加入“WPF C#”之类的内容。这就是标签的用途。 –

+0

当您在调试器中查看textFeedbackFeedback.Text时,它显示了什么? – itowlson

回答

5

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

如果不工作,尝试找出文本的长度,并在文本chracters的整数/ ASCII值。

+0

检查文本的长度,所有其他方法不起作用。谢谢您的帮助。 –

+0

没问题.. :) –

0

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