Partilhar via


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.

testObject.GetCurrentPattern(ItemContainerPattern.Pattern)

                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.

(bool)item.GetCurrentPropertyValue(AutomationElementIdentifiers.IsVirtualizedItemPatternAvailableProperty);

 

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

 

UIA.zip

Comments

  • Anonymous
    November 16, 2009
    This is good news: previously I've resorted to work-arounds like scrolling through every item in a virtualized list to force them to be realized. Is this going to be introduced in Silverlight as well?

  • Anonymous
    November 20, 2009
    currently this is an unsupported feature in SL