2015-02-12 79 views
-2

如何在文本框上設置驗證錯誤? 例如,如果用戶插入少於12個字,它將顯示。 如果用戶插入的數目將顯示 驗證我想顯示在標籤在文本框中設置驗證

<TextBox HorizontalAlignment="Left" Height="23" Margin="41,69,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="200" Grid.Column="1"/> TextBox控件的

<Label Content="Label" HorizontalAlignment="Left" Margin="40,176,0,0" VerticalAlignment="Top"/>

回答

0

使用文本改變事件。你會使用下面的代碼

private void textbox1_TextChanged(object sender, TextChangedEventArgs e) 
{ 
    string[] arrWords = textbox1.Text.Split(new char[] { ' ' }); 
     int count = arrWords.Length.ToString(); 
     if(count<12) 
      { 
       label1.Content="enter your error message"; 
      } 

} 
得到文本框中輸入的單詞數