Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
IsTopmost Property

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)

public bool IsTopmost { get; }

Property Value

Type: System.Boolean
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
    }
}

.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