System.Windows.Automation.TreeWalker.GetParent C# (CSharp) Method

GetParent() public method

public GetParent ( AutomationElement element ) : AutomationElement
element AutomationElement
return AutomationElement
        public AutomationElement GetParent(AutomationElement element)
        {
            return GetParent(element, CacheRequest.Current);
        }

Same methods

TreeWalker::GetParent ( AutomationElement element, CacheRequest request ) : AutomationElement

Usage Example

        private AutomationElement GetAncestorWithHandle(AutomationElement element)
        {
            try
            {
                var walker = new TreeWalker(Condition.TrueCondition);
                var testParent = walker.GetParent(element);

                while (testParent != null && testParent.Current.NativeWindowHandle == 0)
                {
                    testParent = walker.GetParent(testParent);

                    if (
                        testParent != null &&
                        testParent.Current.ProcessId > 0 &&
                        testParent.Current.NativeWindowHandle != 0
                    )
                        return testParent;
                }

                return
                    testParent.Current.NativeWindowHandle != 0
                    ? testParent
                    : null;
            }
            catch
            {
                return null;
            }
        }
All Usage Examples Of System.Windows.Automation.TreeWalker::GetParent