ScrollItemPattern.ScrollIntoView Methode

Definition

Führt einen Bildlauf im Inhaltsbereich eines Containerobjekts durch, um das AutomationElement im sichtbaren Bereich (Viewport) des Containers anzuzeigen.Scrolls the content area of a container object in order to display the AutomationElement within the visible region (viewport) of the container.

public:
 void ScrollIntoView();
public void ScrollIntoView ();
member this.ScrollIntoView : unit -> unit
Public Sub ScrollIntoView ()

Ausnahmen

Das Element konnte nicht durch einen Bildlauf sichtbar gemacht werden.The item could not be scrolled into view.

Beispiele

Im folgenden Beispiel wurde ein- Select ,- AddToSelection oder- RemoveFromSelection Ereignishandler deklariert, mit dem versucht wird, ein- SelectionItemPattern Objekt in den sichtbaren Bereich seines Container Steuer Elements zu scrollen.In the following example, a Select, AddToSelection or RemoveFromSelection event handler has been declared that attempts to scroll a SelectionItemPattern object into the viewable region of its container control.

///--------------------------------------------------------------------
/// <summary>
/// Obtains a ScrollItemPattern control pattern from an 
/// automation element.
/// </summary>
/// <param name="targetControl">
/// The automation element of interest.
/// </param>
/// <returns>
/// A ScrollItemPattern object.
/// </returns>
///--------------------------------------------------------------------
private ScrollItemPattern GetScrollItemPattern(
    AutomationElement targetControl)
{
    ScrollItemPattern scrollItemPattern = null;

    try
    {
        scrollItemPattern =
            targetControl.GetCurrentPattern(
            ScrollItemPattern.Pattern)
            as ScrollItemPattern;
    }
    // Object doesn't support the ScrollItemPattern control pattern
    catch (InvalidOperationException)
    {
        return null;
    }

    return scrollItemPattern;
}
'''--------------------------------------------------------------------
''' <summary>
''' Obtains a ScrollItemPattern control pattern from an 
''' automation element.
''' </summary>
''' <param name="targetControl">
''' The automation element of interest.
''' </param>
''' <returns>
''' A ScrollItemPattern object.
''' </returns>
'''--------------------------------------------------------------------
Private Function GetScrollItemPattern( _
ByVal targetControl As AutomationElement) As ScrollItemPattern
    Dim scrollItemPattern As ScrollItemPattern = Nothing

    Try
        scrollItemPattern = DirectCast( _
        targetControl.GetCurrentPattern( _
        scrollItemPattern.Pattern), ScrollItemPattern)
    Catch
        ' Object doesn't support the ScrollItemPattern control pattern
        Return Nothing
    End Try

    Return scrollItemPattern

End Function 'GetScrollItemPattern    
///--------------------------------------------------------------------
/// <summary>
/// A Select, AddToSelection or RemoveFromSelection event handler that 
/// scrolls a SelectionItem object into the viewable region of its 
/// container control.
/// </summary>
///--------------------------------------------------------------------
private void OnSelectionItemSelect(
    object src, SelectionChangedEventArgs e)
{
    AutomationElement selectionItem = src as AutomationElement;

    ScrollItemPattern scrollItemPattern = GetScrollItemPattern(selectionItem);

    if (scrollItemPattern == null)
    {
        return;
    }

    try
    {
        scrollItemPattern.ScrollIntoView();
    }
    catch (InvalidOperationException)
    {
        // The item cannot be scrolled into view.
        // TO DO: error handling.
    }
}
'''--------------------------------------------------------------------
''' <summary>
''' A Select, AddToSelection or RemoveFromSelection event handler that 
''' scrolls a SelectionItem object into the viewable region of its 
''' container control.
''' </summary>
'''--------------------------------------------------------------------
Private Sub OnSelectionItemSelect( _
ByVal src As Object, ByVal e As SelectionChangedEventArgs)
    Dim selectionItem As AutomationElement = _
    DirectCast(src, AutomationElement)

    Dim scrollItemPattern As ScrollItemPattern = _
    GetScrollItemPattern(selectionItem)

    If scrollItemPattern Is Nothing Then
        Return
    End If

    Try
        scrollItemPattern.ScrollIntoView()
    Catch exc As InvalidOperationException
        ' The item cannot be scrolled into view.
        ' TO DO: error handling.
    End Try

End Sub

Hinweise

Diese Methode bietet nicht die Möglichkeit, die Position des AutomationElement im sichtbaren Bereich (Viewport) des Containers anzugeben.This method does not provide the ability to specify the position of the AutomationElement within the visible region (viewport) of the container.

Gilt für: