首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何访问现有AutomationPeer的基础元素?

如何访问现有AutomationPeer的基础元素?
EN

Stack Overflow用户
提问于 2014-05-23 18:31:24
回答 1查看 830关注 0票数 0

我最近开始学习/使用AutomationPeer类以及如何重写它的特性。我有一个问题,就是是否要提取在初始化UIElement时传入的AutomationPeer。

举个例子:

代码语言:javascript
复制
public class MyRadMenuItemAutomationPeer : RadMenuItemAutomationPeer
{
    public MyRadMenuItemAutomationPeer(RadMenuItem owner)
      : base(owner)
    {

    }

    protected override List<AutomationPeer> GetChildrenCore()
    {
        //originalPeers at this point is a collection of RadMenuItemAutomationPeer
        var originalPeers = base.GetChildrenCore();
        
        //Id like to take each one of these Peers, and somehow cast them or 
        // create a new collection<MyRadMenuItemAutomationPeer> from the root
        // element in the original peer. I know there is the Owner property but
        // that is protected and not visible from the outside.

        var newPeers = 
             //What should be implemented here? An idea I had is something like:
             // originalPeers.Select(p => new MyRadMenuItemAutomationPeer(p.Element))
            //     .ToList(); where p.Element is the way to get the element

        //return newPeers Collection
        return newPeers;
    }

    protected override string GetNameCore()
    {
        //Logic to determing the name Property
        return nameValue;
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-05-28 17:50:09

Simon Mourier提出的解决方案非常有效。他把它作为一个子评论,所以我不能标记它作为一个回答。

从AutomationPeer派生的许多类都具有一个所有者属性,该属性通常对应于相关的“对象”。对于UIElementAutomationPeer,所有者是相关的UIElement。因此,您可以尝试将任何AutomationPeer转换为给定的派生类,并检查它。这就是你要找的吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23836177

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档