I have an application that consumes LayoutUpdated-events and need to register them weak. Here is the problem, I got stuck on, during implementation of the WeakEventManager
internal class WeakLayoutUpdatedManager : WeakEventManager
{
[..]
private void OnLayoutUpdated(object sender, EventArgs e)
{
// NOTE: received sender is always null (by design of LayoutUpdated)
base.DeliverEvent(sender, e);
}
}
That's what happens:
- we always receive null as sender (by design of LayoutUpdated)
- that null gets passed into DeliverEvent
- DeliverEvent can not lookup the correct ListenerList, because it needs a sender != null as key
the failing lookup in WPF: WeakEventManager // DeliverEvent // Line: 359
object sourceKey = (sender != null) ? sender : StaticSource;
list = (ListenerList)Table[this, sourceKey];
My question is: is there a way to weak-register to LayoutUpdated event?
I'm not interested in the sender-parameter, so it's ok to me that LayoutUpdated always delivers null (my actual implemention with regular "+=" works). But the WeakEventManager base-class relies on the sender-parameter to keep track of the ListenerLists.