0

以下のコードでわかるように、HouseholdNoTextBox に 2 つ以上の整数があるかどうかを確認する方法のみを調べています。

private void btnContinue1_Click(object sender, RoutedEventArgs e)
    {
        if (string.IsNullOrEmpty(HouseholdNoTextBox.Text))
        {
            textBlockError1.Visibility = Visibility.Visible;
        }
        if (//HouseholdNoTextBox.Text has > than 2 integers input)
        {
            textBlockError1.Visibility = Visibility.Collapsed; // collapse the first error box if it is visible
            textBlockError2.Visibility = Visibility.Visible; // and make visible the second
        }
    }
4

2 に答える 2

1

これを試して

private void btnContinue1_Click(object sender, RoutedEventArgs e)
    {
        if (string.IsNullOrEmpty(HouseholdNoTextBox.Text))
        {
            textBlockError1.Visibility = Visibility.Visible;
        }
int val;
        if (HouseholdNoTextBox.Text.Length>2 && int.TryParse(HouseholdNoTextBox.Text, out val) && val > 99)
        {
            textBlockError1.Visibility = Visibility.Collapsed; // collapse the first error box if it is visible
            textBlockError2.Visibility = Visibility.Visible; // and make visible the second
        }
    }
于 2013-01-23T10:50:21.403 に答える
0

これが私の最終的な作業コードです。彼が私を正しい方向に導いてくれるので、サイバーマックスの回答を+1します

private void btnContinue1_Click(object sender, RoutedEventArgs e)
    {
        if (string.IsNullOrEmpty(HouseholdNoTextBox.Text))
        {
            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.Length <= 2 && HouseholdNoTextBox.Text.Length > 0)
        {
            textBlockError1.Visibility = Visibility.Collapsed;
            textBlockError2.Visibility = Visibility.Collapsed;
            NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.Relative));
        }           
    }
于 2013-01-23T11:35:03.400 に答える