Page view counter

Jesse Liberty - Silverlight Geek

More Signal Less Noise

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
Posted: Jan 15 2008, 10:00 AM by jesseliberty | with 7 comment(s)
Filed under:

Comments

DotNetKicks.com said:

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

# January 15, 2008 11:35 AM

Pages tagged "events" said:

Pingback from  Pages tagged "events"

# January 15, 2008 3:26 PM

Blogs said:

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

# February 3, 2008 1:34 PM

Jesse Liberty - Silverlight Geek said:

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

# February 5, 2008 2:10 PM

Jesse Liberty - Silverlight Geek said:

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

# February 5, 2008 2:43 PM

Jesse Liberty said:

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

# February 5, 2008 3:08 PM

Mirrored Blogs said:

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

# February 20, 2008 2:55 AM