다음을 통해 공유


IViewAutomationPeer 인터페이스

정의

ListView에서 파생된 ViewBase의 사용자 지정 뷰에서 사용자 지정 뷰에 고유한 자동화 피어 기능을 구현하도록 허용합니다.

public interface class IViewAutomationPeer
public interface IViewAutomationPeer
type IViewAutomationPeer = interface
Public Interface IViewAutomationPeer
파생

예제

다음 코드를 구현 하는 사용자 지정 보기를 보여 줍니다 IViewAutomationPeer 위쪽에 표시 되는 단추를 처리 하는 별도 클래스에는 ListView 제어 합니다.

public class OneButtonHeaderView : ViewBase
{
    protected override IViewAutomationPeer GetAutomationPeer(ListView parent)
    {
        return new OneButtonHeaderViewAutomationPeer( this, parent );
    }
Public Class OneButtonHeaderView
    Inherits ViewBase
    Protected Overrides Function GetAutomationPeer(ByVal parent As ListView) As IViewAutomationPeer
        Return New OneButtonHeaderViewAutomationPeer(Me, parent)
    End Function
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
        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() { }
}
Public Class OneButtonHeaderViewAutomationPeer
    Implements IViewAutomationPeer
    Private m_lv As ListView

    Public Sub New(ByVal control As OneButtonHeaderView, ByVal parent As ListView)
        m_lv = parent
    End Sub

    Private Function CreateItemAutomationPeer(ByVal item As Object) As ItemAutomationPeer Implements IViewAutomationPeer.CreateItemAutomationPeer
        Dim lvAP As ListViewAutomationPeer = TryCast(UIElementAutomationPeer.FromElement(m_lv), ListViewAutomationPeer)
        Return New ListBoxItemAutomationPeer(item, lvAP)
    End Function

    Private Function GetAutomationControlType() As AutomationControlType Implements IViewAutomationPeer.GetAutomationControlType
        Return AutomationControlType.List
    End Function

    Private Function GetChildren(ByVal children As List(Of AutomationPeer)) As List(Of AutomationPeer) Implements IViewAutomationPeer.GetChildren
        ' 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.

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

        'If children is null, we still need to create an empty list to insert the button
        If children Is Nothing Then
            children = New List(Of AutomationPeer)()
        End If

        children.Insert(0, peer)

        Return children
    End Function

    Private Function GetPattern(ByVal patternInterface As PatternInterface) As Object Implements IViewAutomationPeer.GetPattern
        ' we can invoke the banner button 
        If patternInterface = PatternInterface.Invoke Then
            Dim b As Button = CType(m_lv.Template.FindName("BannerButton", m_lv), Button)
            Dim peer As AutomationPeer = UIElementAutomationPeer.FromElement(b)
            If peer IsNot Nothing Then
                Return peer
            End If
        End If

        ' if this view does not have special handling for the pattern interface, return null
        ' the ListViewAutomationPeer.GetPattern default handling will be used.
        Return Nothing
    End Function

    Private Sub ItemsChanged(ByVal e As System.Collections.Specialized.NotifyCollectionChangedEventArgs) Implements IViewAutomationPeer.ItemsChanged
    End Sub

    Private Sub ViewDetached() Implements IViewAutomationPeer.ViewDetached
    End Sub
End Class

메서드

CreateItemAutomationPeer(Object)

ItemAutomationPeer 클래스의 새 인스턴스를 만듭니다.

GetAutomationControlType()

IViewAutomationPeer와 연결된 요소의 컨트롤 형식을 가져옵니다.

GetChildren(List<AutomationPeer>)

지정된 UI 자동화 피어의 직계 자식 요소 컬렉션을 가져옵니다.

GetPattern(PatternInterface)

지정된 patternInterface와 연결된 컨트롤 패턴을 가져옵니다.

ItemsChanged(NotifyCollectionChangedEventArgs)

항목 컬렉션이 변경될 때 ListView에 의해 호출됩니다.

ViewDetached()

사용자 지정 뷰가 ListView에 더 이상 적용되지 않을 때 호출됩니다.

적용 대상

추가 정보