Keeping track of 'sender'
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:
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: