WynApse Home Page
Home    Blog    Contact       
Latest Article:
Read my CoDe Magazine Article
My Tags:
Hosted by:


3 Months FREE!

Ask me how to get 6 months free.

Running on ASP.Net 2.0

Lifetime Member:
Join Community Credit - I did!




web tracker

Over 1136514 Pages Served


<SilverlightTooltip Number="002" Text="Sender" />



Keeping track of 'sender'

We're all pretty comfortable using 'sender' in our mouse handlers to find other objects by name in our JavaScript, and most of us are familiar with adding onto the main canvas using createFromXaml. Both of these require a valid object, and the createFromXaml has even more stringent requirements.

In our code, we find ourselves passing 'sender' around from function to function, and if we have to do createFromXaml, we end up doing getHost() to find the control itself, then using some other object to also find the canvas.

I have a very simple solution to both of these situations that I've been using...

In your xaml, add a line to your main outer canvas:


Loaded="CanvasLoaded"


Then in your JavaScript, you can add a global variable:


var mainCanvas = null;


and a function:

function CanvasLoaded(sender, args)
{
mainCanvas = sender;
}


We KNOW that the sender is the main canvas, so we automatically get a valid 'sender' plus we have our canvas as an object variable that we can now use to find any other object using:

mainCanvas.findName("something");


or to use adding children:

mainCanvas.children.add(TextBlock);

RSS:  rss URL



Member of WPF and Silverlight Insiders
Creative Commons License

Alltop, confirmation that I kick ass
Check out our book:
Our Book
Copyright © 2006-2008, WynApse