DockPattern.SetDockPosition Method (DockPosition)

 

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.

Exception Condition
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
Available since 3.0
Return to top
Show: