Follow me on Twitter!
(0 votes)

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

0 comments   /   aggregated from   Silverlight Brass Tacks on Apr 23, 2008  /  original article

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.

Filed under: Misc


Comments

Comments RSS RSS
No comments

Add Comment