FrameworkElementAutomationPeer.FromElement method

Returns the FrameworkElementAutomationPeer for the specified UIElement.

Syntax


public static AutomationPeer FromElement(
  UIElement element
)

Parameters

element

Type: UIElement

The UIElement that is associated with this FrameworkElementAutomationPeer.

Return value

Type: AutomationPeer

The FrameworkElementAutomationPeer, or null if the FrameworkElementAutomationPeer could not be created.

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.

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);
    }
}


Requirements (device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.UI.Xaml.Automation.Peers
Windows::UI::Xaml::Automation::Peers [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (operating system)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml.Automation.Peers
Windows::UI::Xaml::Automation::Peers [C++]

Metadata

Windows.winmd

See also

FrameworkElementAutomationPeer
CreatePeerForElement

 

 

Show:
© 2015 Microsoft