Export (0) Print
Expand All

ScrollPattern.ScrollVertical Method

Scrolls the currently visible region of the content area, vertically, the specified ScrollAmount.

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

public void ScrollVertical(
	ScrollAmount amount
)

Parameters

amount
Type: System.Windows.Automation.ScrollAmount

The vertical ScrollAmount increment specific to the control.

ExceptionCondition
ArgumentException

If a control supports SmallIncrement values exclusively for horizontal or vertical scrolling but a LargeIncrement value is passed in.

InvalidOperationException

An attempt is made to scroll in an unsupported direction.

In the following example, a ScrollPattern control pattern is obtained from an AutomationElement and is then used to vertically scroll the element a requested amount.

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

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

    return scrollPattern;
}


...


///-------------------------------------------------------------------- 
/// <summary> 
/// Obtains a ScrollPattern control pattern from an automation  
/// element and attempts to horizontally scroll the requested amount. 
/// </summary> 
/// <param name="targetControl">
/// The automation element of interest. 
/// </param> 
/// <param name="vScrollAmount">
/// The requested vertical scroll amount. 
/// </param> 
///-------------------------------------------------------------------- 
private void ScrollElementVertically(
    AutomationElement targetControl,
    ScrollAmount vScrollAmount)
{
    if (targetControl == null)
    {
        throw new ArgumentNullException(
            "AutomationElement argument cannot be null.");
    }

    ScrollPattern scrollPattern = GetScrollPattern(targetControl);

    if (scrollPattern == null)
    {
        return;
    }

    if (!scrollPattern.Current.VerticallyScrollable)
    {
        return;
    }

    try
    {
        scrollPattern.ScrollVertical(vScrollAmount);
    }
    catch (InvalidOperationException)
    {
        // Control not able to scroll in the direction requested; 
        // when scrollable property of that direction is False 
        // TO DO: error handling.
    }
    catch (ArgumentException)
    {
        // If a control supports SmallIncrement values exclusively  
        // for horizontal or vertical scrolling but a LargeIncrement  
        // value (NaN if not supported) is passed in. 
        // TO DO: error handling.
    }
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft