Page view counter

Did You Know That... You can put events into your XAML or into the code behind?

There are two common idioms for creating events (and wiring up their handlers) for XAML objects.

One is to place the name of the event and the name of its handler in the XAML itself

<Canvas
 Canvas.Top="180"
 Canvas.Left="200"      
 MouseLeftButtonDown="onMouseDown"
 MouseLeftButtonUp="onMouseUp"
 MouseMove="onMouseMove">

The other is to create a link between a reference to the XAML object and its handler in the code-behind; typically in the handler for page load

this.button.addEventListener("MouseLeftButtonDown", Silverlight.createDelegate(this, this.handleMouseDown));
this.button.addEventListener("MouseLeftButtonUp", Silverlight.createDelegate(this, this.handleMouseUp));
this.button.addEventListener("MouseLeave", Silverlight.createDelegate(this, this.handleMouseLeave));

The CreateDelegate method ensures that the event is correctly routed. This method is created for you by the Silverlight 1.0 template in Visual Studio.

Silverlight.createDelegate = function(instance, method)
{
    return function() 
    {
        return method.apply(instance, arguments);
    }
}
kick it on DotNetKicks.com
Published 15 January 2008 10:00 AM by jesseliberty
Filed under:

Comments

# DotNetKicks.com said on 15 January, 2008 11:35 AM

You've been kicked (a good thing) - Trackback from DotNetKicks.com

# Pages tagged "events" said on 15 January, 2008 03:26 PM

Pingback from  Pages tagged "events"

# Blogs said on 03 February, 2008 01:34 PM

A very insightful reader sent me email that I&#39;m going to respond to here. To protect his identity

# Jesse Liberty - Silverlight Geek said on 05 February, 2008 02:10 PM

Got a nice international email today that said in part... ...things get more interesting it is a common

# Jesse Liberty - Silverlight Geek said on 05 February, 2008 02:43 PM

A very insightful reader sent me email that I&#39;m going to respond to here. To protect his identity

# Jesse Liberty said on 05 February, 2008 03:08 PM

Got a nice international email today that said in part... ...things get more interesting it is a common

# Mirrored Blogs said on 20 February, 2008 02:55 AM

Got a nice international email today that said in part... ...things get more interesting it is a common