Export (0) Print
Expand All

PresentationSource.AddSourceChangedHandler Method

Adds a handler for the SourceChanged event to the provided element.

Namespace:  System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

[UIPermissionAttribute(SecurityAction.LinkDemand, Window = UIPermissionWindow.AllWindows)]
public static void AddSourceChangedHandler(
	IInputElement element,
	SourceChangedEventHandler handler
)

Parameters

element
Type: System.Windows.IInputElement

The element to add the handler to.

handler
Type: System.Windows.SourceChangedEventHandler

The hander implementation to add.

Despite what the syntax block for this event states, there is no legitimate Extensible Application Markup Language (XAML) attached property usage. You should not attempt to add handlers in Extensible Application Markup Language (XAML), and handlers in code should only be placed on objects that serve as hosts for presentation (PresentationSource ) content. Such handlers should only be attached during object initialization, and should be explicitly removed in a Dispose method or equivalent object cleanup.

Even though this is a routed event, there are special restrictions placed on this event that differ from normal routed event behavior, due to the relatively small number of elements in a typical application scenario that would concern themselves with handling this event.

  • You cannot use the UIElement or ContentElement AddHandler methods to add handlers. You must use AddSourceChangedHandler.

  • The C# += and -= event handler syntaxes, and related language specific handler syntaxes, are not supported, because the event itself is not exposed as public. Only the PresentationSource utility methods for adding and removing the handlers directly are supported.

  • Class handlers are not allowed. Specifically, you cannot call RegisterClassHandler against this event in a class constructor because although an identifier field exists for SourceChanged, the identifier is not public.

  • All registered handlers will receive the SourceChanged event even if one of the handlers attempts to mark the arguments as handled.

.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