DependencyObject.AddHandler(DependencyProperty, Object) Método

Definición

Agrega un controlador para un evento de DependencyObject.Adds a handler for an event of a DependencyObject.

public:
 void AddHandler(System::Workflow::ComponentModel::DependencyProperty ^ dependencyEvent, System::Object ^ value);
public void AddHandler (System.Workflow.ComponentModel.DependencyProperty dependencyEvent, object value);
member this.AddHandler : System.Workflow.ComponentModel.DependencyProperty * obj -> unit
Public Sub AddHandler (dependencyEvent As DependencyProperty, value As Object)

Parámetros

value
Object

La clase Object que representa el valor de esta propiedad.The Object that represents the value of this property. En este caso, un tipo Delegate.In this case, a Delegate type.

Excepciones

Cualquiera de los argumentos son una referencia nula (Nothing en Visual Basic).Either of the arguments is a null reference (Nothing in Visual Basic).

El valor es de Type incorrecto.Value is of incorrect Type

o bien-or-

dependencyEvent representa DependencyProperty de un no evento.The dependencyEvent represents a non-event DependencyProperty.

Ejemplos

Los controladores se agregan y se quitan utilizando el código siguiente.Handlers are added and removed using the following code. Este ejemplo de código forma parte del ejemplo de SDK de envío de correo electrónico y se encuentra en el archivo SendMailActivity. cs.This code example is part of the Send Email SDK sample and is from the SendMailActivity.cs file. Para obtener más información, vea ejemplo de actividad de envío de correo electrónico.For more information, see Send Email Activity Sample.

#region Public Events

[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[Description("The SendingEmail event is raised before an email is sent through SMTP.")]
[Category(EventsCategory)]
[Browsable(true)]
public event EventHandler SendingEmail
{
    add
    {
        base.AddHandler(SendEmailActivity.SendingEmailEvent, value);
    }
    remove
    {
        base.RemoveHandler(SendEmailActivity.SendingEmailEvent, value);
    }
}


#Region "Public Events"

        <DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)> _
        <Description("The SendingEmail event is raised before an email is sent through SMTP.")> _
        <Category(EventsCategory)> _
        <Browsable(True)> _
        Public Custom Event SendingEmail As EventHandler
            AddHandler(ByVal value As EventHandler)
                MyBase.AddHandler(SendEmailActivity.SendingEmailEvent, value)
            End AddHandler

            RemoveHandler(ByVal value As EventHandler)
                MyBase.RemoveHandler(SendEmailActivity.SendingEmailEvent, value)
            End RemoveHandler

            RaiseEvent(ByVal sender As Object, ByVal e As System.EventArgs)

            End RaiseEvent
        End Event


Comentarios

Cuando crea un delegado, identifica el método que controla el evento.When you create a delegate, you identify the method that handles the event. Para asociar el evento al controlador, se debe agregar una instancia del delegado al evento.To associate the event with your event handler, add an instance of the delegate to the event. A menos que se quite el delegado, siempre que se produzca el evento se llamará al controlador de eventos.Unless you remove the delegate, the event handler is called whenever the event occurs. Se pueden agregar varios delegados para controlar un evento.Multiple delegates can be added to handle an event. Para obtener más información sobre los delegados de controladores de eventos, vea controlar y provocar eventos.For more information about event-handler delegates, see Handling and Raising Events.

Se aplica a