Редагувати

Поділитися через


PresentationSource.AddSourceChangedHandler Method

Definition

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

public:
 static void AddSourceChangedHandler(System::Windows::IInputElement ^ element, System::Windows::SourceChangedEventHandler ^ handler);
[System.Security.SecurityCritical]
public static void AddSourceChangedHandler (System.Windows.IInputElement element, System.Windows.SourceChangedEventHandler handler);
public static void AddSourceChangedHandler (System.Windows.IInputElement element, System.Windows.SourceChangedEventHandler handler);
[<System.Security.SecurityCritical>]
static member AddSourceChangedHandler : System.Windows.IInputElement * System.Windows.SourceChangedEventHandler -> unit
static member AddSourceChangedHandler : System.Windows.IInputElement * System.Windows.SourceChangedEventHandler -> unit
Public Shared Sub AddSourceChangedHandler (element As IInputElement, handler As SourceChangedEventHandler)

Parameters

element
IInputElement

The element to add the handler to.

handler
SourceChangedEventHandler

The handler implementation to add.

Attributes

Remarks

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.

Applies to