Why does ListBoxItem.OnCreateAutomationPeer() return a ListBoxItemWrapperAutomationPeer?

269 views Asked by At

In .NET Framework 4.7.1, ListBoxItem.OnCreateAutomationPeer() returns a ListBoxItemWrapperAutomationPeer.

Does anybody know why it does not return a ListBoxItemAutomationPeer? It would be much more usefull since ListBoxItemWrapperAutomationPeer does not do anything but ListBoxItemPeer allows Selection pattern.

1

There are 1 answers

0
jchristin On

I just found the answer in the internal comments of the class 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.

see https://referencesource.microsoft.com/#PresentationCore/Core/CSharp/System/Windows/Automation/Peers/AutomationPeer.cs,1350