public static FindVisualAncestor ( this startElement, Predicate | ||
startElement | this | The start element. |
condition | Predicate | The condition. |
maxDepth | int | The maximum number of levels to go up when searching for the parent. If smaller than 0, no maximum is used. |
return | object |
public static object FindVisualAncestor(this UIView startElement, Predicate<object> condition, int maxDepth = -1)
{
var obj = startElement;
while ((obj != null) && !condition(obj))
{
if (maxDepth == 0)
{
return null;
}
else if (maxDepth > 0)
{
maxDepth--;
}
obj = obj.GetVisualParent();
}
return obj;
}