Skip Navigation LinksHome / Articles / View Article

Why would you specify an event handler in XAML instead of code?

+ Add to SilverlightShow Favorites
0 comments   /   aggregated from Silverlight Brass Tacks on Apr 23, 2008  /  original article
(0 votes)
Categories: Misc

Forgive me if I'm being dense and this was obvious to other people, but I have been wondering about this for while.

In most demos I see by the Silverlight Team and others, they typically declare the event handler in the XAML:

"rect" MouseEnter="rect_MouseEnter"/>

As a developer, it seems to me like this is a strange mix of code and design time stuff, and it would be cleaner to wire up the event handler in code, and then all of the event handling code is in one place.

I guess the key to this is that I am a developer, and that's how developers think. The problem with doing this in code is that designers then need you to change some code if they want to change the visual element that the MouseEnter event is wired to. If, however, the event handler is wired up in XAML, then the designer can move that event to some other element, and as long as the event handler code doesn't do anything specific to that particular element, it should all still work.

In this world of tighter integration in the designer-developer workflow, there will be a lot of little things like this that developers will need to get used to.

Share


Comments

Comments RSS RSS
No comments

Add Comment

 
 

   
  
  
   
Please add 7 and 5 and type the answer here:

Join the free SilverlightShow webcast 'Running Silverlight Outside the Browser and with Elevated Trust'. Sept 7th, 8 am - 9 am PDT.
In this live session Chris Anderson will cover configuring and debugging OOB mode, toast notifications, elevated trust, direct file access and much more.
Learn more | Register | See more webinars (hide this)