This is the simplest way to do it.
private Point startpoint;
private Rectangle rect;
private void canvas1_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
startpoint = Mouse.GetPosition(canvas1);
rect = new Rectangle();
rect.Stroke = Brushes.Black;
rect.StrokeThickness = 1;
canvas1.Children.Add(rect);
}
private void canvas1_MouseMove(object sender, MouseEventArgs e)
{
if (rect != null)
{
rect.Width = 5;
rect.Height = 6;
}
}