using System.Windows.Controls;
namespace ECMonitor.MVVM
{
	public class WPFAssist
	{
		/// 
		/// 获取DataGrid的所有行是否存在验证错误。
		/// 
		/// 要检查的DataGrid实例
		/// true 有错,false 无错
		public static bool GetDataGridRowsHasError(DataGrid dg)
		{
			bool hasError = false;
			ValidationError err = null;
			for (int i = 0; i < dg.Items.Count; i++)
			{
				DataGridRow row = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(i);
				hasError = Validation.GetHasError(row);
				if (hasError)
				{
					break;
				}
			}
			return hasError;
		}
		/// 
		/// 获取DataGrid的第一个被发现的验证错误结果。
		/// 
		/// 被检查的DataGrid实例。
		/// 错误结果。
		public static ValidationError GetDataGridRowsFirstError(DataGrid dg)
		{
			bool hasError = false;
			ValidationError err = null;
			for (int i = 0; i < dg.Items.Count; i++)
			{
				DataGridRow row = (DataGridRow)dg.ItemContainerGenerator.ContainerFromIndex(i);
				hasError = Validation.GetHasError(row);
				if (hasError)
				{
					err = Validation.GetErrors(row)[0];
					break;
				}
			}
			return err;
		}
	}
}