WindowPattern.WindowPatternInformation.IsTopmost Property

Gets a value that specifies whether the AutomationElement is the topmost element in the z-order.

Namespace: System.Windows.Automation
Assembly: UIAutomationClient (in uiautomationclient.dll)
XML Namespace:  http://schemas.microsoft.com/winfx/2006/xaml/presentation

public bool IsTopmost { get; }
/** @property */
public boolean get_IsTopmost ()

public function get IsTopmost () : boolean

Not applicable.

Property Value

true if the AutomationElement is topmost; otherwise false.

In the following example, an AutomationPropertyChangedEventHandler is defined to listen for changes to the IsTopmostProperty of an AutomationElement.

    ///--------------------------------------------------------------------
    /// <summary>
    /// Register for automation property change events of interest.
    /// </summary>
    /// <param name="targetControl">
    /// The automation element of interest.
    /// </param>
    ///--------------------------------------------------------------------
    private void RegisterForPropertyChangedEvents(
        AutomationElement targetControl)
    {
        AutomationPropertyChangedEventHandler propertyChangeListener = 
            new AutomationPropertyChangedEventHandler(
            OnTopmostPropertyChange);
        Automation.AddAutomationPropertyChangedEventHandler(
            targetControl, 
            TreeScope.Element, 
            propertyChangeListener, 
            WindowPattern.IsTopmostProperty);
    }

...

    ///--------------------------------------------------------------------
    /// <summary>
    /// Register for automation property change events of interest.
    /// </summary>
    /// <param name="src">Object that raised the event.</param>
    /// <param name="e">Event arguments.</param>
    ///--------------------------------------------------------------------
    private void OnTopmostPropertyChange(object src, AutomationPropertyChangedEventArgs e)
    {
        // Make sure the element still exists. Elements such as tooltips
        // can disappear before the event is processed.
        AutomationElement sourceElement;
        try
        {
            sourceElement = src as AutomationElement;
        }
        catch (ElementNotAvailableException)
        {
            return;
        }
        
        // Get a WindowPattern from the source of the event.
        WindowPattern windowPattern = GetWindowPattern(sourceElement);
        if (windowPattern.Current.IsTopmost)
        {
            //TODO: event handling
        }
    }

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0

Community Additions

ADD
Show: