Click or drag to resize
DigitalRuneWeakEventT Class
Represents an event that stores the target objects as weak references.
Inheritance Hierarchy
SystemObject
  DigitalRuneWeakMulticastDelegate
    DigitalRuneWeakMulticastDelegateT
      DigitalRuneWeakEventT

Namespace: DigitalRune
Assembly: DigitalRune (in DigitalRune.dll) Version: 1.20.0.0 (1.20.1.14552)
Syntax
public sealed class WeakEvent<T> : WeakMulticastDelegate<T>
where T : class

Type Parameters

T
The type of event handler. Must be of type EventHandler or EventHandlerTEventArgs.

The WeakEventT type exposes the following members.

Constructors
  NameDescription
Public methodWeakEventT
Initializes a new instance of the WeakEventT class
Top
Methods
  NameDescription
Public methodAdd(Delegate)
Adds a new Delegate to the WeakMulticastDelegate.
(Inherited from WeakMulticastDelegate.)
Public methodAdd(T) (Inherited from WeakMulticastDelegateT.)
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodInvoke(Object)
Invokes the stored Delegates with the given arguments.
(Inherited from WeakMulticastDelegate.)
Public methodInvoke(Object, EventArgs)
Raises the event.
Public methodRemove(Delegate)
Removes a Delegate from the WeakMulticastDelegate.
(Inherited from WeakMulticastDelegate.)
Public methodRemove(T) (Inherited from WeakMulticastDelegateT.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Properties
  NameDescription
Public propertyCount
Gets the number of live delegates in the collection.
(Inherited from WeakMulticastDelegate.)
Top
Remarks
Important: In Silverlight, the event handlers that handle the weak event need to be public methods (no private, protected or anonymous methods). This is necessary because of security restrictions in Silverlight.
Examples
The following examples shows how a class can implement a weak event.
C#
class MyEventSource
{
  private readonly WeakEvent<EventHandler<EventArgs>> _myEvent = new WeakEvent<EventHandler<EventArgs>>();

  public event EventHandler<EventArgs> MyEvent
  {
    add { _myEvent.Add(value); }
    remove { _myEvent.Remove(value); }
  }

  protected virtual void OnMyEvent(EventArgs eventArgs)
  {
    _myEvent.Invoke(this, eventArgs);
  }  
}
See Also