在 .NET Framework 4.7.1 中,ListBoxItem.OnCreateAutomationPeer()返回一个 ListBoxItemWrapperAutomationPeer。
有人知道为什么它不返回 ListBoxItemAutomationPeer 吗?它会更有用,因为 ListBoxItemWrapperAutomationPeer 不做任何事情,但 ListBoxItemPeer 允许选择模式。
在 .NET Framework 4.7.1 中,ListBoxItem.OnCreateAutomationPeer()返回一个 ListBoxItemWrapperAutomationPeer。
有人知道为什么它不返回 ListBoxItemAutomationPeer 吗?它会更有用,因为 ListBoxItemWrapperAutomationPeer 不做任何事情,但 ListBoxItemPeer 允许选择模式。
我刚刚在 AutomationPeer 类的内部注释中找到了答案:
// For ItemsControls, there are typically two different peers for each
// (visible) item: an "item" peer and a "wrapper" peer. The former
// corresponds to the item itself, the latter to the container. (These
// are different peers, even when the item is its own container.) The item
// peer appears as a child of the ItemsControl's peer, while the wrapper
// peer is what you get by asking the container for its peer directly.
// For example, a ListBoxAutomationPeer holds children of type
// ListBoxItemAutomationPeer, while the peer for a ListBoxItem has type
// ListBoxItemWrapperAutomationPeer.