FrameworkElementAutomationPeer FrameworkElementAutomationPeer FrameworkElementAutomationPeer Class

Definition

Exposes FrameworkElement derived types (including all controls) to Microsoft UI Automation.

public : class FrameworkElementAutomationPeer : AutomationPeer, IFrameworkElementAutomationPeer
public class FrameworkElementAutomationPeer : AutomationPeer, IFrameworkElementAutomationPeer
Public Class FrameworkElementAutomationPeer Inherits AutomationPeer Implements IFrameworkElementAutomationPeer
Inheritance
FrameworkElementAutomationPeerFrameworkElementAutomationPeerFrameworkElementAutomationPeer
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Examples

This example shows the basic subclass requirements for deriving a peer from FrameworkElementAutomationPeer and supporting at least one control pattern. This code is an excerpt from the XAML accessibility sample.

        public class MediaContainerAP : FrameworkElementAutomationPeer, IRangeValueProvider, IToggleProvider
        {
            MediaElement _mediaElement;
            FrameworkElement _labeledBy;
// nondefault ctors omitted
            protected override object GetPatternCore(PatternInterface patternInterface)
            {
                if (patternInterface == PatternInterface.RangeValue)
                {
                    return this;
                }
                else if (patternInterface == PatternInterface.Toggle)
                {
                    return this;
                }
                return null;
            }


            protected override AutomationControlType GetAutomationControlTypeCore()
            {
                return AutomationControlType.Group;
            }

            protected override string GetLocalizedControlTypeCore()
            {
                return "Video";
            }

            protected override string GetClassNameCore()
            {
                return "MediaElementContainer";
            }
// pattern implementation omitted ...
        }
    Public Class MediaContainerAP
        Inherits FrameworkElementAutomationPeer
        Implements IRangeValueProvider
        Implements IToggleProvider
' nondefault ctors omitted ...

        Protected Overrides Function GetPatternCore(patternInterface__1 As PatternInterface) As Object
            If patternInterface__1 = PatternInterface.RangeValue Then
                Return Me
            ElseIf patternInterface__1 = PatternInterface.Toggle Then
                Return Me
            End If
            Return Nothing
        End Function


        Protected Overrides Function GetAutomationControlTypeCore() As AutomationControlType
            Return AutomationControlType.Group
        End Function

        Protected Overrides Function GetLocalizedControlTypeCore() as String
            Return "Video"
        End Function

        Protected Overrides Function GetClassNameCore() As String
            Return "MediaElementContainer"
        End Function
' pattern implementation omitted ...
End Class
// header
        public ref class MediaContainerAP sealed :  Windows::UI::Xaml::Automation::Peers::FrameworkElementAutomationPeer
                                                    ,Windows::UI::Xaml::Automation::Provider::IRangeValueProvider
                                                    ,Windows::UI::Xaml::Automation::Provider::IToggleProvider
        {
// nondefault ctors omitted
        protected: 
            virtual Object^ GetPatternCore(PatternInterface patternInterface) override
            {
                if (patternInterface == PatternInterface::RangeValue)
                {
                    return this;
                }
                else if (patternInterface == PatternInterface::Toggle)
                {
                    return this;
                }
                return nullptr;
            }

        protected:
            virtual  AutomationControlType GetAutomationControlTypeCore() override
            {
                return  AutomationControlType::Group;
            }

        protected:
            virtual Platform::String^ GetLocalizedControlTypeCore() override
            {
                return "Video";
            }

        protected:
            virtual Platform::String^ GetClassNameCore() override
            {
                return "MediaElementContainer";
            }
// pattern implementation omitted

Remarks

There is no "ControlAutomationPeer" class. FrameworkElementAutomationPeer serves as implementation for all basic Control class scenarios that involve Microsoft UI Automation. This includes behavior that does not necessarily appear as a public API exposure, such as the practical implementations of many of the Core methods from AutomationPeer.

FrameworkElementAutomationPeer includes extensive base implementation of peer behavior that other peers can use to report information that comes from owner classes at the UIElement and FrameworkElement level. For more info, see the "Base implementation in FrameworkElementAutomationPeer" section of Custom automation peers.

In addition to the Core overrides, FrameworkElementAutomationPeer has two static utility methods that are useful for getting a peer handle from within control code, or for generating items peers from an item container peer for Microsoft UI Automation support. These are:

If you have a need to define a custom automation peer and can't identify a more derived peer class that pairs up with the control or base class you are deriving the owner class from, you should base your peer on FrameworkElementAutomationPeer. Even if the owner class isn't necessarily a FrameworkElement, you can't practically derive peers from AutomationPeer directly because FrameworkElementAutomationPeer has many overrides that provide the expected behavior for layout, automation and UI interactions. You do need to derive your owner class from UIElement at least, otherwise there is no way to create the peer on automation tree load with OnCreateAutomationPeer.

FrameworkElementAutomationPeer derived classes

FrameworkElementAutomationPeer is the parent class for several immediately derived classes that implement peer support for Windows Runtime controls and elements. Some of these peer classes are peers that match control base classes rather than practical controls. For example ButtonBaseAutomationPeer exists so that it can define shared peer behavior for several classes that support the practical Button classes that derive from ButtonBase. Here is the list of classes that directly derive from FrameworkElementAutomationPeer:

Constructors

FrameworkElementAutomationPeer(FrameworkElement) FrameworkElementAutomationPeer(FrameworkElement) FrameworkElementAutomationPeer(FrameworkElement)

Initializes a new instance of the FrameworkElementAutomationPeer class.

public : FrameworkElementAutomationPeer(FrameworkElement owner)
public FrameworkElementAutomationPeer(FrameworkElement owner)
Public Sub New(owner As FrameworkElement)
Parameters
owner
FrameworkElement FrameworkElement FrameworkElement

The owner element to create for.

Properties

Dispatcher Dispatcher Dispatcher

Inherited from DependencyObject

EventsSource EventsSource EventsSource

Inherited from AutomationPeer

Owner Owner Owner

Gets the UIElement owner that is associated with this FrameworkElementAutomationPeer.

public : UIElement Owner { get; }
public UIElement Owner { get; }
Public ReadOnly Property Owner As UIElement
Value
UIElement UIElement UIElement

The element that owns this instance of the peer class.

Methods

ClearValue(DependencyProperty) ClearValue(DependencyProperty) ClearValue(DependencyProperty)

Inherited from DependencyObject

CreatePeerForElement(UIElement) CreatePeerForElement(UIElement) CreatePeerForElement(UIElement)

Creates a FrameworkElementAutomationPeer for the specified UIElement.

public : static AutomationPeer CreatePeerForElement(UIElement element)
public static AutomationPeer CreatePeerForElement(UIElement element)
Public Static Function CreatePeerForElement(element As UIElement) As AutomationPeer
Parameters
element
UIElement UIElement UIElement

The UIElement that is associated with this FrameworkElementAutomationPeer.

Returns

Examples

CreatePeerForElement is useful if you are writing a peer that forwards the peer information from one of its component parts, because it's the component part that might implement a pattern as requested in the peer's GetPatternCore implementation. For example, if one of a control's main component parts is a ScrollViewer the control itself may have some other function and doesn't scroll directly. But the peer might still want to report support for a Scroll pattern, and provide a peer so that a client can interact with the automation pattern of the scrolling part.

protected override object GetPatternCore(PatternInterface patternInterface)
{
    if (patternInterface == PatternInterface.Scroll)
    {
        ItemsControl owner = (ItemsControl) base.Owner;
        UIElement itemsHost = owner.ItemsHost;
        ScrollViewer element = null;
        while (itemsHost != owner)
        {
            itemsHost = VisualTreeHelper.GetParent(itemsHost) as UIElement;
            element = itemsHost as ScrollViewer;
            if (element != null)
            {
                break;
            }
        }
        if (element != null)
        {
            AutomationPeer peer = FrameworkElementAutomationPeer.CreatePeerForElement(element);
            if ((peer != null) && (peer is IScrollProvider))
            {
                return (IScrollProvider) peer;
            }
        }
    }
    return base.GetPatternCore(patternInterface);
}

Remarks

CreatePeerForElement is a helper class that is used by custom control code to return the acting peer instance. Using the returned peer, you can fire automation events from within the same routines that also fire your general control logic events or change control properties. Or you can write your own helper methods that do this and are invoked from your control logic.

The created FrameworkElementAutomationPeer remains in memory until the associated UIElement is destroyed. The same instance of the FrameworkElementAutomationPeer is returned from subsequent calls to CreatePeerForElement and calls to FromElement that reference the same element instance.

The type of the peer returned is determined by the OnCreateAutomationPeer implementation of the relevant UIElement, which is typically a Control. If the class code for the element type doesn't implement OnCreateAutomationPeer, no peer is created, and CreatePeerForElement returns null. As a best practice you should always check for null after calling CreatePeerForElement, because there are a number of Windows Runtime elements that won't have an OnCreateAutomationPeer implementation. For example, a ContentControl doesn't have a peer by default unless it's customized or is a more-derived Windows Runtime control.

CreatePeerForElement has basically the same behavior as FromElement.

CreatePeerForElement can return the peer even if the CreateAutomationPeer system logic hasn't run yet on the element target for some reason. It will invoke the same CreateAutomationPeer logic internally in order to get the peer.

See Also

FromElement(UIElement) FromElement(UIElement) FromElement(UIElement)

Returns the FrameworkElementAutomationPeer for the specified UIElement.

public : static AutomationPeer FromElement(UIElement element)
public static AutomationPeer FromElement(UIElement element)
Public Static Function FromElement(element As UIElement) As AutomationPeer
Parameters
element
UIElement UIElement UIElement

The UIElement that is associated with this FrameworkElementAutomationPeer.

Returns

Examples

The automation support design doesn't retain a handle to your own peer as part of how you implement OnCreateAutomationPeer, because there aren't any guarantees of when the peer is actually created. Instead, you can check for run-time automation event listeners inside your control class definitions just-in-time, using code like this:

if (AutomationPeer.ListenerExists(AutomationEvents.PropertyChanged))
{
    MyAutomationPeer peer = 
        FrameworkElementAutomationPeer.FromElement(myCtrl) as MyAutomationPeer;

    if (peer != null)
    {
        peer.RaisePropertyChangedEvent(
            RangeValuePatternIdentifiers.ValueProperty,
            (double)oldValue,
            (double)newValue);
    }
}
If AutomationPeer.ListenerExists(AutomationEvents.PropertyChanged) Then
    Dim peer As MyDownAutomationPeer = _
    TryCast(FrameworkElementAutomationPeer.FromElement(myCtrl), MyAutomationPeer)
    If peer IsNot Nothing Then
        peer.RaisePropertyChangedEvent(RangeValuePatternIdentifiers.ValueProperty, CDbl(oldValue), CDbl(newValue))
    End If
End If

Remarks

FromElement is a helper class that is used by custom control code to return the acting peer instance. Using the returned peer, you can fire automation events from within the same routines that also fire your general control logic events or change control properties. Or you can write your own helper methods that do this and are invoked from your control logic.

CreatePeerForElement has basically the same behavior as FromElement.

If FromElement returns null, it's probably because the element you passed does not have an implementation for OnCreateAutomationPeer.

FromElement can return the peer even if the CreateAutomationPeer system logic hasn't run yet on the element target for some reason. It will invoke the same CreateAutomationPeer logic internally in order to get the peer.

See Also

GenerateRawElementProviderRuntimeId GenerateRawElementProviderRuntimeId GenerateRawElementProviderRuntimeId

Inherited from AutomationPeer

GetAcceleratorKey GetAcceleratorKey GetAcceleratorKey

Inherited from AutomationPeer

GetAcceleratorKeyCore GetAcceleratorKeyCore GetAcceleratorKeyCore

Inherited from AutomationPeer

GetAccessKey GetAccessKey GetAccessKey

Inherited from AutomationPeer

GetAccessKeyCore GetAccessKeyCore GetAccessKeyCore

Inherited from AutomationPeer

GetAnimationBaseValue(DependencyProperty) GetAnimationBaseValue(DependencyProperty) GetAnimationBaseValue(DependencyProperty)

Inherited from DependencyObject

GetAnnotations GetAnnotations GetAnnotations

Inherited from AutomationPeer

GetAnnotationsCore GetAnnotationsCore GetAnnotationsCore

Inherited from AutomationPeer

GetAutomationControlType GetAutomationControlType GetAutomationControlType

Inherited from AutomationPeer

GetAutomationControlTypeCore GetAutomationControlTypeCore GetAutomationControlTypeCore

Inherited from AutomationPeer

GetAutomationId GetAutomationId GetAutomationId

Inherited from AutomationPeer

GetAutomationIdCore GetAutomationIdCore GetAutomationIdCore

Inherited from AutomationPeer

GetBoundingRectangle GetBoundingRectangle GetBoundingRectangle

Inherited from AutomationPeer

GetBoundingRectangleCore GetBoundingRectangleCore GetBoundingRectangleCore

Inherited from AutomationPeer

GetChildren GetChildren GetChildren

Inherited from AutomationPeer

GetChildrenCore GetChildrenCore GetChildrenCore

Inherited from AutomationPeer

GetClassName GetClassName GetClassName

Inherited from AutomationPeer

GetClassNameCore GetClassNameCore GetClassNameCore

Inherited from AutomationPeer

GetClickablePoint GetClickablePoint GetClickablePoint

Inherited from AutomationPeer

GetClickablePointCore GetClickablePointCore GetClickablePointCore

Inherited from AutomationPeer

GetControlledPeers GetControlledPeers GetControlledPeers

Inherited from AutomationPeer

GetControlledPeersCore GetControlledPeersCore GetControlledPeersCore

Inherited from AutomationPeer

GetCulture GetCulture GetCulture

Inherited from AutomationPeer

GetCultureCore GetCultureCore GetCultureCore

Inherited from AutomationPeer

GetDescribedByCore GetDescribedByCore GetDescribedByCore

Inherited from AutomationPeer

GetElementFromPoint(Point) GetElementFromPoint(Point) GetElementFromPoint(Point)

Inherited from AutomationPeer

GetElementFromPointCore(Point) GetElementFromPointCore(Point) GetElementFromPointCore(Point)

Inherited from AutomationPeer

GetFlowsFromCore GetFlowsFromCore GetFlowsFromCore

Inherited from AutomationPeer

GetFlowsToCore GetFlowsToCore GetFlowsToCore

Inherited from AutomationPeer

GetFocusedElement GetFocusedElement GetFocusedElement

Inherited from AutomationPeer

GetFocusedElementCore GetFocusedElementCore GetFocusedElementCore

Inherited from AutomationPeer

GetFullDescription GetFullDescription GetFullDescription

Inherited from AutomationPeer

GetFullDescriptionCore GetFullDescriptionCore GetFullDescriptionCore

Inherited from AutomationPeer

GetHelpText GetHelpText GetHelpText

Inherited from AutomationPeer

GetHelpTextCore GetHelpTextCore GetHelpTextCore

Inherited from AutomationPeer

GetItemStatus GetItemStatus GetItemStatus

Inherited from AutomationPeer

GetItemStatusCore GetItemStatusCore GetItemStatusCore

Inherited from AutomationPeer

GetItemType GetItemType GetItemType

Inherited from AutomationPeer

GetItemTypeCore GetItemTypeCore GetItemTypeCore

Inherited from AutomationPeer

GetLabeledBy GetLabeledBy GetLabeledBy

Inherited from AutomationPeer

GetLabeledByCore GetLabeledByCore GetLabeledByCore

Inherited from AutomationPeer

GetLandmarkType GetLandmarkType GetLandmarkType

Inherited from AutomationPeer

GetLandmarkTypeCore GetLandmarkTypeCore GetLandmarkTypeCore

Inherited from AutomationPeer

GetLevel GetLevel GetLevel

Inherited from AutomationPeer

GetLevelCore GetLevelCore GetLevelCore

Inherited from AutomationPeer

GetLiveSetting GetLiveSetting GetLiveSetting

Inherited from AutomationPeer

GetLiveSettingCore GetLiveSettingCore GetLiveSettingCore

Inherited from AutomationPeer

GetLocalizedControlType GetLocalizedControlType GetLocalizedControlType

Inherited from AutomationPeer

GetLocalizedControlTypeCore GetLocalizedControlTypeCore GetLocalizedControlTypeCore

Inherited from AutomationPeer

GetLocalizedLandmarkType GetLocalizedLandmarkType GetLocalizedLandmarkType

Inherited from AutomationPeer

GetLocalizedLandmarkTypeCore GetLocalizedLandmarkTypeCore GetLocalizedLandmarkTypeCore

Inherited from AutomationPeer

GetName GetName GetName

Inherited from AutomationPeer

GetNameCore GetNameCore GetNameCore

Inherited from AutomationPeer

GetOrientation GetOrientation GetOrientation

Inherited from AutomationPeer

GetOrientationCore GetOrientationCore GetOrientationCore

Inherited from AutomationPeer

GetParent GetParent GetParent

Inherited from AutomationPeer

GetPattern(PatternInterface) GetPattern(PatternInterface) GetPattern(PatternInterface)

Inherited from AutomationPeer

GetPatternCore(PatternInterface) GetPatternCore(PatternInterface) GetPatternCore(PatternInterface)

Inherited from AutomationPeer

GetPeerFromPoint(Point) GetPeerFromPoint(Point) GetPeerFromPoint(Point)

Inherited from AutomationPeer

GetPeerFromPointCore(Point) GetPeerFromPointCore(Point) GetPeerFromPointCore(Point)

Inherited from AutomationPeer

GetPositionInSet GetPositionInSet GetPositionInSet

Inherited from AutomationPeer

GetPositionInSetCore GetPositionInSetCore GetPositionInSetCore

Inherited from AutomationPeer

GetSizeOfSet GetSizeOfSet GetSizeOfSet

Inherited from AutomationPeer

GetSizeOfSetCore GetSizeOfSetCore GetSizeOfSetCore

Inherited from AutomationPeer

GetValue(DependencyProperty) GetValue(DependencyProperty) GetValue(DependencyProperty)

Inherited from DependencyObject

HasKeyboardFocus HasKeyboardFocus HasKeyboardFocus

Inherited from AutomationPeer

HasKeyboardFocusCore HasKeyboardFocusCore HasKeyboardFocusCore

Inherited from AutomationPeer

InvalidatePeer InvalidatePeer InvalidatePeer

Inherited from AutomationPeer

IsContentElement IsContentElement IsContentElement

Inherited from AutomationPeer

IsContentElementCore IsContentElementCore IsContentElementCore

Inherited from AutomationPeer

IsControlElement IsControlElement IsControlElement

Inherited from AutomationPeer

IsControlElementCore IsControlElementCore IsControlElementCore

Inherited from AutomationPeer

IsDataValidForForm IsDataValidForForm IsDataValidForForm

Inherited from AutomationPeer

IsDataValidForFormCore IsDataValidForFormCore IsDataValidForFormCore

Inherited from AutomationPeer

IsEnabled IsEnabled IsEnabled

Inherited from AutomationPeer

IsEnabledCore IsEnabledCore IsEnabledCore

Inherited from AutomationPeer

IsKeyboardFocusable IsKeyboardFocusable IsKeyboardFocusable

Inherited from AutomationPeer

IsKeyboardFocusableCore IsKeyboardFocusableCore IsKeyboardFocusableCore

Inherited from AutomationPeer

IsOffscreen IsOffscreen IsOffscreen

Inherited from AutomationPeer

IsOffscreenCore IsOffscreenCore IsOffscreenCore

Inherited from AutomationPeer

IsPassword IsPassword IsPassword

Inherited from AutomationPeer

IsPasswordCore IsPasswordCore IsPasswordCore

Inherited from AutomationPeer

IsPeripheral IsPeripheral IsPeripheral

Inherited from AutomationPeer

IsPeripheralCore IsPeripheralCore IsPeripheralCore

Inherited from AutomationPeer

IsRequiredForForm IsRequiredForForm IsRequiredForForm

Inherited from AutomationPeer

IsRequiredForFormCore IsRequiredForFormCore IsRequiredForFormCore

Inherited from AutomationPeer

ListenerExists(AutomationEvents) ListenerExists(AutomationEvents) ListenerExists(AutomationEvents)

Inherited from AutomationPeer

Navigate(AutomationNavigationDirection) Navigate(AutomationNavigationDirection) Navigate(AutomationNavigationDirection)

Inherited from AutomationPeer

NavigateCore(AutomationNavigationDirection) NavigateCore(AutomationNavigationDirection) NavigateCore(AutomationNavigationDirection)

Inherited from AutomationPeer

PeerFromProvider(IRawElementProviderSimple) PeerFromProvider(IRawElementProviderSimple) PeerFromProvider(IRawElementProviderSimple)

Inherited from AutomationPeer

ProviderFromPeer(AutomationPeer) ProviderFromPeer(AutomationPeer) ProviderFromPeer(AutomationPeer)

Inherited from AutomationPeer

RaiseAutomationEvent(AutomationEvents) RaiseAutomationEvent(AutomationEvents) RaiseAutomationEvent(AutomationEvents)

Inherited from AutomationPeer

RaiseNotificationEvent(AutomationNotificationKind,AutomationNotificationProcessing,String,String) RaiseNotificationEvent(AutomationNotificationKind,AutomationNotificationProcessing,String,String) RaiseNotificationEvent(AutomationNotificationKind,AutomationNotificationProcessing,String,String)

Inherited from AutomationPeer

RaisePropertyChangedEvent(AutomationProperty,Object,Object) RaisePropertyChangedEvent(AutomationProperty,Object,Object) RaisePropertyChangedEvent(AutomationProperty,Object,Object)

Inherited from AutomationPeer

RaiseStructureChangedEvent(AutomationStructureChangeType,AutomationPeer) RaiseStructureChangedEvent(AutomationStructureChangeType,AutomationPeer) RaiseStructureChangedEvent(AutomationStructureChangeType,AutomationPeer)

Inherited from AutomationPeer

RaiseTextEditTextChangedEvent(AutomationTextEditChangeType,IVectorView{String}) RaiseTextEditTextChangedEvent(AutomationTextEditChangeType,IVectorView{String}) RaiseTextEditTextChangedEvent(AutomationTextEditChangeType,IVectorView{String})

Inherited from AutomationPeer

ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty) ReadLocalValue(DependencyProperty)

Inherited from DependencyObject

RegisterPropertyChangedCallback(DependencyProperty,DependencyPropertyChangedCallback) RegisterPropertyChangedCallback(DependencyProperty,DependencyPropertyChangedCallback) RegisterPropertyChangedCallback(DependencyProperty,DependencyPropertyChangedCallback)

Inherited from DependencyObject

SetFocus SetFocus SetFocus

Inherited from AutomationPeer

SetFocusCore SetFocusCore SetFocusCore

Inherited from AutomationPeer

SetParent(AutomationPeer) SetParent(AutomationPeer) SetParent(AutomationPeer)

Inherited from AutomationPeer

SetValue(DependencyProperty,Object) SetValue(DependencyProperty,Object) SetValue(DependencyProperty,Object)

Inherited from DependencyObject

ShowContextMenu ShowContextMenu ShowContextMenu

Inherited from AutomationPeer

ShowContextMenuCore ShowContextMenuCore ShowContextMenuCore

Inherited from AutomationPeer

UnregisterPropertyChangedCallback(DependencyProperty,Int64) UnregisterPropertyChangedCallback(DependencyProperty,Int64) UnregisterPropertyChangedCallback(DependencyProperty,Int64)

Inherited from DependencyObject

See Also