Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API to access parent of the UIItem found via Get methods #139

Closed
ivan-danilov opened this issue Aug 2, 2013 · 1 comment
Closed

API to access parent of the UIItem found via Get methods #139

ivan-danilov opened this issue Aug 2, 2013 · 1 comment

Comments

@ivan-danilov
Copy link
Contributor

In WPF where Templates are used heavily it is often the case that the easiest way to find something is by text and as a result we have some kind of Label, which is not very useful. It'd be great to have either a way to obtain a parent of given UIItem or at least to have API to obtain not only search target, but also entire path of UIItems in automation elements hierarchy that leads to that search target.

For example, if I have custom data template for ListBoxItem or TreeViewItem - I have "list item"/"tree item" as containers and icon plus label underneath. Without API for getting parent item - it is not easy to obtain UIItem for "tree item" - e.g. if I want to expand it - because it has no distinguished properties like its child label.

@JakeGinnivan
Copy link
Member

Thanks for the suggestion.

For the moment you could use this extension method

public static class UIItemExtensions
{
    public static T GetParent<T>(this IUIItem uiItem) where T : IUIItem
    {
        var parent = TreeWalker.ControlViewWalker.GetParent(uiItem.AutomationElement);
        var uiItem = new DictionaryMappedItemFactory().Create(parent, uiItem.ActionListener);
        return UIItemProxyFactory.Create(uiItem, uiItem.ActionListener);
    }
}

You can also use the ControlViewWalker to get different controls around it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants