You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.3 KiB
50 lines
1.3 KiB
3 years ago
|
using System.Windows.Controls;
|
||
|
|
||
|
namespace ECMonitor.MVVM
|
||
|
{
|
||
|
public class WPFAssist
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 获取DataGrid的所有行是否存在验证错误。
|
||
|
/// </summary>
|
||
|
/// <param name="dg">要检查的DataGrid实例</param>
|
||
|
/// <returns>true 有错,false 无错</returns>
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取DataGrid的第一个被发现的验证错误结果。
|
||
|
/// </summary>
|
||
|
/// <param name="dg">被检查的DataGrid实例。</param>
|
||
|
/// <returns>错误结果。</returns>
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
}
|