Welcome to WindowsClient.net | My Blog | Sign in | Join

Rob Relyea - XAMLified

WPF, Silverlight and XAML

Syndication

Sponsors





  • advertise here
Double event firing in VB/XAML. How common?

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….

Published Monday, November 16, 2009 8:18 AM by Rob_Relyea

Comments

# re: Double event firing in VB/XAML. How common?@ Tuesday, November 17, 2009 4:11 AM

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.

by James Chaldecott

# Dew Drop – November 17, 2009 | Alvin Ashcraft's Morning Dew@ Tuesday, November 17, 2009 8:20 AM

Pingback from  Dew Drop – November 17, 2009 | Alvin Ashcraft's Morning Dew

Leave a Comment

(required) 
(required) 
(optional)
(required)