WPF, Silverlight and XAML
Jonathan Aneja blogged for the VB Team about cases where a developer creates an event handler in XAML and uses the Handles clause on a method. You end up with the same event firing twice.
A XamlFxCop rule could be written to help detect this case. See the #pdc09 XAML Futures talk on Thursday in LA or soon afterwards online to learn more about #XAMLFxCop.
Should the XAML Compiler + VB Compiler be enhanced to check for this as well? Let’s talk Jonathan….
I'd prefer it if you/they could fix what I imagine is the underlying issue:
If you subscribe to a RoutedEvent twice with the same handler, then the handler actually gets called twice every time the event is raised. Also, you have to unsubscribe twice. This is not the same as normal .Net events, which will ignore a second subscription from the same handler.
I had this issue when subscribing the the Unloaded event when I got the Loaded event (& then vice-versa). It turned out that if I got the Loaded event more than once for a particular element (which is surprisingly common) then I'd end up with mismatched subscriptions and unsubscriptions, and I then ended up with increasing numbers of unwanted subscriptions as the elements were loaded & unloaded.
Pingback from Dew Drop – November 17, 2009 | Alvin Ashcraft's Morning Dew