IViewAutomationPeer Interface
TOC
Collapse the table of content
Expand the table of content

IViewAutomationPeer Interface

 

Allows a customized view of a ListView that derives from ViewBase to implement automation peer features that are specific to the custom view.

Namespace:   System.Windows.Automation.Peers
Assembly:  PresentationFramework (in PresentationFramework.dll)

public interface IViewAutomationPeer

NameDescription
System_CAPS_pubmethodCreateItemAutomationPeer(Object)

Creates a new instance of the ItemAutomationPeer class.

System_CAPS_pubmethodGetAutomationControlType()

Gets the control type for the element that is associated with this IViewAutomationPeer.

System_CAPS_pubmethodGetChildren(List<AutomationPeer>)

Gets the collection of immediate child elements of the specified UI Automation peer.

System_CAPS_pubmethodGetPattern(PatternInterface)

Gets the control pattern that is associated with the specified patternInterface.

System_CAPS_pubmethodItemsChanged(NotifyCollectionChangedEventArgs)

Called by ListView when the collection of items changes.

System_CAPS_pubmethodViewDetached()

Called when the custom view is no longer applied to the ListView.

The following code shows a custom view implementing IViewAutomationPeer in a separate class to handle a button that appears at the top of the ListView control.

public class OneButtonHeaderView : ViewBase
{
    protected override IViewAutomationPeer GetAutomationPeer(ListView parent)
    {
        return new OneButtonHeaderViewAutomationPeer( this, parent );
    }
public class OneButtonHeaderViewAutomationPeer : IViewAutomationPeer
{
    ListView m_lv;

    public OneButtonHeaderViewAutomationPeer(OneButtonHeaderView control, ListView parent)
    {
        m_lv = parent;
    }

    ItemAutomationPeer IViewAutomationPeer.CreateItemAutomationPeer(Object item)
    {
        ListViewAutomationPeer lvAP = UIElementAutomationPeer.FromElement(m_lv) as ListViewAutomationPeer;
        return new ListBoxItemAutomationPeer(item, lvAP);
    }

    AutomationControlType IViewAutomationPeer.GetAutomationControlType()
    {
        return AutomationControlType.List;
    }

    List<AutomationPeer> IViewAutomationPeer.GetChildren(List<AutomationPeer> children)
    {
        // the children parameter is a list of automation peers for all the known items
        // our view must add its banner button peer to this list.

        Button b = (Button)m_lv.Template.FindName("BannerButton", m_lv);
        AutomationPeer peer = UIElementAutomationPeer.CreatePeerForElement(b);

        //If children is null, we still need to create an empty list to insert the button
        if (children == null)
        {
            children = new List<AutomationPeer>();
        }

        children.Insert(0, peer);

        return children;
    }

    Object IViewAutomationPeer.GetPattern(PatternInterface patternInterface)
    {
        // we can invoke the banner button 
        if (patternInterface == PatternInterface.Invoke)
        {
            Button b = (Button)m_lv.Template.FindName("BannerButton", m_lv);
            AutomationPeer peer = UIElementAutomationPeer.FromElement(b);
            if (peer != null)
                return peer;
        }

        // if this view does not have special handling for the pattern interface, return null
        // the ListViewAutomationPeer.GetPattern default handling will be used.
        return null;
    }

    void IViewAutomationPeer.ItemsChanged(System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { }

    void IViewAutomationPeer.ViewDetached() { }
}

.NET Framework
Available since 3.0
Return to top
Show:
© 2016 Microsoft