我最近开始学习/使用AutomationPeer类以及如何重写它的特性。我有一个问题,就是是否要提取在初始化UIElement时传入的AutomationPeer。
举个例子:
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;
}
}发布于 2014-05-28 17:50:09
Simon Mourier提出的解决方案非常有效。他把它作为一个子评论,所以我不能标记它作为一个回答。
从AutomationPeer派生的许多类都具有一个所有者属性,该属性通常对应于相关的“对象”。对于UIElementAutomationPeer,所有者是相关的UIElement。因此,您可以尝试将任何AutomationPeer转换为给定的派生类,并检查它。这就是你要找的吗?
https://stackoverflow.com/questions/23836177
复制相似问题