New WPF Features: UIA Virtualization

Pre .NET 4, from a UI automation perspective, virtualization was not a good story. There wasn’t a standard way of dealing with virtualized controls, since some would expose only the visual elements while the others would create an automation tree that had every element. To fix this problem, in .NET 4, we have introduced 2 new UIA patterns: ItemContainerPattern\VirtualizedItemPattern

ItemContainerPattern enables searching the whole tree irrespective of it being virtualized.


                Search is done using the FindItemByProperty function which has 3 parameters

- AutomationElement startAfter: element to start search from. Setting to null would mean start from beginning

- AutomationProperty: Property to be used for search. Setting to null corresponds to match all properties

- Object value: Property value

Once you find the element, you can then determine if it’s virtualized by querying the IsVirtualizedItemPatternAvailable.



So you have the virtualized item and would like to de-virtualize it.

VirtualizedItemPattern vpattern = item.GetCurrentPattern(VirtualizedItemPattern.Pattern) as VirtualizedItemPattern;

vpattern.Realize(); // de-virtualize the object


You can also query if the ItemContainerPattern is available using the property IsItemContainerPatternAvailable.

Sample project showing usage is attached.

Share this post