Export (0) Print
Expand All

ScrollItemPattern.ScrollIntoView Method

Scrolls the content area of a container object in order to display the AutomationElement within the visible region (viewport) of the container.

Namespace:  System.Windows.Automation
Assembly:  UIAutomationClient (in UIAutomationClient.dll)

public void ScrollIntoView()

ExceptionCondition
InvalidOperationException

The item could not be scrolled into view.

This method does not provide the ability to specify the position of the AutomationElement within the visible region (viewport) of the container.

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> 
/// 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.
    }
}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft