Aplicativos do Windows
Recolher sumário
Expandir sumário
Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

UIElement.OnCreateAutomationPeer method

When implemented in a derived class, returns class-specific AutomationPeer implementations for the Microsoft UI Automation infrastructure.


protected virtual AutomationPeer OnCreateAutomationPeer()


This method has no parameters.

Return value

Type: AutomationPeer

The class-specific AutomationPeer subclass to return.


For more info on the purpose of an automation peer and why you might need to define a class-specific AutomationPeer class, see Custom automation peers.

You should override this method in a custom class where you want to supply a custom automation peer for UI Automation, rather than the default peer that is referenced by the default OnCreateAutomationPeer implementation. How you define a custom peer for your custom control depends on your control's accessibility requirements , its UI contract, and its behavior. For more info on why you might want to define a new peer, see Custom automation peers. To see a sample that implements OnCreateAutomationPeer and defines the custom peer that OnCreateAutomationPeer returns, see XAML accessibility sample (the peer implementation is part of Scenario 3 in that sample).

We recommend that the OnCreateAutomationPeer implementation should do nothing more than initialize a new instance of your custom automation peer, passing the calling control as owner, and return that instance. Do not attempt additional logic in this method. In particular, any logic that could potentially lead to destruction of the AutomationPeer within the same call may result in unexpected runtime behavior.


The entirety of a OnCreateAutomationPeer implementation should consist of constructing the custom automation peer class and returning it.

        protected override AutomationPeer OnCreateAutomationPeer() 
            return new MediaContainerAP(this, mediaElement); 

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::UI::Xaml [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]


Windows::UI::Xaml [C++]



See also

XAML accessibility sample
Custom automation peers



© 2016 Microsoft