1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
-
- using System.Collections.Generic;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- namespace FWindSoft.Wpf
- {
- /// <summary>
- /// 依赖属性扩展
- /// </summary>
- public static class DependencyObjectExtensions
- {
- public static bool HasError(this DependencyObject depObject)
- {
- bool flag = false;
- #region 验证修改
- if (Validation.GetHasError(depObject))
- {
- flag = true;
- return flag;
- }
- #endregion
- for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObject); i++)
- {
- var child = VisualTreeHelper.GetChild(depObject, i);
- if (child.HasError())
- {
- flag = true;
- break;
- }
- }
- return flag;
- }
- /// <summary>
- /// 判定元素是否错误
- /// </summary>
- /// <param name="depObject"></param>
- /// <param name="errorObject">返回错误元素</param>
- /// <returns></returns>
- public static bool HasError(this DependencyObject depObject,out DependencyObject errorObject)
- {
- bool flag = false;
- errorObject = null;
- if (Validation.GetHasError(depObject))
- {
- flag = true;
- errorObject = depObject;
- return flag;
- }
- for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObject); i++)
- {
- var child = VisualTreeHelper.GetChild(depObject, i);
- if (child.HasError(out errorObject))
- {
- flag = true;
- break;
- }
- }
- return flag;
- }
- public static List<T> GetSpecifyTypeChildren<T>(this DependencyObject dependencyObject) where T : DependencyObject
- {
- List<T> list = new List<T>();
- for (int i = 0; i < VisualTreeHelper.GetChildrenCount(dependencyObject); i++)
- {
- var child = VisualTreeHelper.GetChild(dependencyObject, i);
- if (child is T)
- {
- list.Add((T)child);
- continue;
- }
- list.AddRange(child.GetSpecifyTypeChildren<T>());
- }
- return list;
- }
- }
- }
|