public static INameScope FindNameScope(this ILogical control) { Contract.Requires <ArgumentNullException>(control != null); return(control.GetSelfAndLogicalAncestors() .OfType <StyledElement>() .Select(x => (x as INameScope) ?? NameScope.GetNameScope(x)) .FirstOrDefault(x => x != null)); }
public static INameScope?FindNameScope(this ILogical control) { _ = control ?? throw new ArgumentNullException(nameof(control)); var scope = control.GetSelfAndLogicalAncestors() .OfType <StyledElement>() .Select(x => (x as INameScope) ?? NameScope.GetNameScope(x)) .FirstOrDefault(x => x != null); return(scope); }
/// <summary> /// Return a parent of the ILogical indicated /// </summary> /// <param name="Logical">The control to get its parent</param> /// <returns>the parent of the control</returns> public static T GetParentTOfLogical <T>(this ILogical logical) where T : class { return(logical.GetSelfAndLogicalAncestors().OfType <T>().FirstOrDefault <T>()); }