My Silverlight skills are improving and I have now created a Silverlight selection rectangle. You can use this in your application to select stuff. The code is located in the RectangleSelect.js file. I have added a example website, so you can see how to use it. If you don't want to look at the sample website here is basically how:
Set up a load handler in the xaml file:
[code:xml]
<Canvas ... Loaded="load">
[/code]
Implement it:
[code:js]
function load(sender,args){
//create rectangle
var oSelect = new SelectRectangle();
//initialize the rectangle with the root element in the xaml file
oSelect.initRectangle(sender.getHost().content.root);
//handle selected event
oSelect.addSelected(onSelected);
}
[/code]
Pick up the onSelected event after the user has selected something in the canvas:
[code:js]
function onSelected(posRect){
alert("Width: " + posRect.width
+ ", height: " + posRect.height
+ ", x:" + posRect.x
+ ", y: " + posRect.y);
}
[/code]
You can even enable/disable the selection by using
[code:js]
oSelect.enabled = true;
oSelect.enabled = false;
[/code]
The current code is actually a selection square, and not a rectangle. I just forgot to implement it. Converting the code to a selection rectangle and not a square can easily be done by replacing a single line of code. But I'll leave that up to you ;)
Sample web site (28.68 kb)