WynApse Home Page
Home    Blog    About    Contact       
Latest Article:

My Tags:
My Sponsors:

Lifetime Member:

<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:


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:


or to use adding children:

Copyright © 2006-2022, WynApse