Export (0) Print
Expand All

DockPattern.SetDockPosition Method

Docks the AutomationElement at the requested DockPosition within a docking container.

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

public void SetDockPosition(
	DockPosition dockPosition
)

Parameters

dockPosition
Type: System.Windows.Automation.DockPosition

The dock position relative to the boundaries of the docking container and other elements within the container.

ExceptionCondition
InvalidOperationException

When a control is not able to execute the requested dock style.

A docking container is a control that allows the arrangement of child elements, both horizontally and vertically, relative to the boundaries of the docking container and other elements within the container.

In the following example, an AutomationElement representing a control that supports the DockPattern control pattern has its dockPosition modified.

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

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

    return dockPattern;
}


...


///-------------------------------------------------------------------- 
/// <summary> 
/// Sets the dock position of a target. 
/// </summary> 
/// <param name="dockControl">
/// The automation element of interest. 
/// </param> 
/// <param name="dockPosition">
/// The requested DockPosition. 
/// </param> 
///-------------------------------------------------------------------- 
private void SetDockPositionOfControl(
    AutomationElement dockControl, DockPosition dockPosition)
{
    if (dockControl == null)
    {
        throw new ArgumentNullException(
            "AutomationElement parameter must not be null.");
    }

    try
    {
        DockPattern dockPattern = GetDockPattern(dockControl);
        if (dockPattern == null)
        {
            return;
        }
        dockPattern.SetDockPosition(dockPosition);
    }
    catch (InvalidOperationException)
    {
        // When a control is not able to dock. 
        // TO DO: error handling
    }
}

.NET Framework

Supported in: 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