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
)
You cannot use methods in XAML.

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.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft