//... static LayoutGroupControl GetParent(this ILayoutControl input, LayoutGroupControl parent = null) { if (parent == null) { if (ReferenceEquals(input.Root.Child, input)) { return(null); } if (input.Root.Child is LayoutGroupControl i) { return(input.GetParent(i)); } } foreach (var i in parent.Children) { if (ReferenceEquals(i, input)) { return(parent); } if (i is LayoutGroupControl j) { var result = input.GetParent(j); if (result != null) { return(result); } } } return(null); }
public static List <T> GetAll <T>(this ILayoutControl input, LayoutGroupControl parent = null) where T : Content { var result = new List <T>(); if (parent == null) { foreach (var i in GetAll <T>(input)) { result.Add(i); } return(result); } foreach (var i in parent.Children) { foreach (var j in GetAll <T>(i as ILayoutControl)) { result.Add(j); } } return(result); }
public static void EachControl <T>(this ILayoutControl input, Action <T> action, LayoutGroupControl parent = null) where T : LayoutContentGroupControl { if (parent == null) { EachControl(input, action); return; } foreach (var i in parent.Children) { EachControl(i as ILayoutControl, action); } }