When you create a rectangle add an event handler:
System.Windows.Shapes.Rectangle rect = new System.Windows.Shapes.Rectangle();
rect.MouseLeftButtonDown += rect_MouseLeftButtonDown;
// apply margins and what not
Then you handle your mouse left button down here:
void rect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var rect = sender as System.Windows.Shapes.Rectangle;
// do whatever
}