The Nito.Mvvm.Core library has a WeakCanExecuteChagned
that makes weak events using a class of commands that you could use as a starting point for writing your manager, supported by WeakCollection<EventHandler>
.
Here is a simple example of using a custom class with an event named Foo
that accepts a FooEventArgs
object.
public class MyClass { private readonly WeakCollection<EventHandler<FooEventArgs>> _foo = new WeakCollection<EventHandler<FooEventArgs>>(); public event EventHandler<FooEventArgs> Foo { add { lock (_foo) { _foo.Add(value); } } remove { lock (_foo) { _foo.Remove(value); } } } protected virtual void OnFoo(FooEventArgs args) { lock (_foo) { foreach (var foo in _foo.GetLiveItems()) { foo(this, args); } } } }
source share