「。」かどうかを確認する方法 TextBoxに入力されましたか?
それは次のようなものですか?
if (TextBox1.Text == ".")
{
//Do something...
}
これを行うと、TextBox1の内容をチェックせず、次のコード行に進むように見えるためです。
これが私のコードです:
private void btnContinue1_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(HouseholdNoTextBox.Text))
{
textBlockError2.Visibility = Visibility.Collapsed;
textBlockError1.Visibility = Visibility.Visible;
}
if (HouseholdNoTextBox.Text.Length >= 3)
{//checking to see if it has a length greater than 2
textBlockError1.Visibility = Visibility.Collapsed; // collapse the first error box if it is visible
textBlockError2.Visibility = Visibility.Visible; // and make visible the second
}
if (HouseholdNoTextBox.Text == ".")
{
textBlockError1.Visibility = Visibility.Visible;
}
if (HouseholdNoTextBox.Text.Length <= 2 && HouseholdNoTextBox.Text.Length > 0)
{
textBlockError1.Visibility = Visibility.Collapsed;
textBlockError2.Visibility = Visibility.Collapsed;
NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
}
私も試しました:
if (HouseholdNoTextBox.Text.Contains("."))
{
textBlockError1.Visibility = Visibility.Visible;
}
私も試しました:
private void btnContinue1_Click(object sender, RoutedEventArgs e)
{
string houseHoldNo = HouseholdNoTextBox.Text.ToString();
if (string.IsNullOrEmpty(HouseholdNoTextBox.Text) || houseHoldNo.Contains(".")) // adding it here along with the first if statement
{
textBlockError2.Visibility = Visibility.Collapsed;
textBlockError1.Visibility = Visibility.Visible;
}
}
私も試しました:
private void btnContinue1_Click(object sender、RoutedEventArgs e){string houseHoldNo = HouseholdNoTextBox.Text.ToString();
if (string.IsNullOrEmpty(HouseholdNoTextBox.Text))
{
textBlockError2.Visibility = Visibility.Collapsed;
textBlockError1.Visibility = Visibility.Visible;
}
if (houseHoldNo.Contains("."))
{
textBlockError1.Visibility = Visibility.Visible;
}
}
上記のコードは他のコードと同じように機能します。最後のifステートメントにスキップします。