using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TextBoxValidation
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            string errMessage = string.Empty;
            foreach (var c in gridRoot.Children) {
                if (c is TextBox) {
                    TextBox textbox = c as TextBox;
                    if (string.IsNullOrEmpty(textbox.Text)) {
                        errMessage += textbox.Tag + "数据未输入.\n";
                    }
                }
            }
            if (errMessage.Length > 0) {
                MessageBox.Show(errMessage, "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
        }
    }
}
