0
votes

XAML

<Canvas x:Name="cvsBurstImage" MouseLeftButtonDown="cvsBurstImage_MouseLeftButtonDown" Style="{StaticResource BurstCanvasStyle}">
   <Viewbox x:Name="vbBurstImage" Style="{StaticResource ViewboxCanvasStyle}">
            <Image x:Name="imgBurstImage" Source="../Assets/Images/default_burst_image.png" ImageFailed="imgBurstImage_ImageFailed"/>
   </Viewbox>                                   
</Canvas>

I am facing a strange problem where i need to draw rectangles on a canvas and make them resizable as well as as moveable (place them anywhere in canvas).

I have achieved this via mouse events of canvas;

  1. private void Canvas_MouseLeftButtonDown(object sender,MouseButtonEventArgs e) {}
  2. private void Canvas_MouseMove(object sender, MouseEventArgs e) {}
  3. private void Canvas_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) {}

Explanation; On MouseLeftButtonDown, i start capturing mouse cordinates and continue doing so with mouse move (make height and width with these cordinates), on MouseLeftButtonUp i stop listening to mouse and draw these cordinates as Rectangle on canvas and add this rectangle to canvas as child element. I also add 3 mouse events to this rectangle;

  1. private void Rectangle_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
  2. private void Rectangle_MouseMove(object sender, MouseEventArgs e)
  3. private void Rectangle_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)

These events i use to identify a given rectangle (Rectangle_MouseLeftButtonDown) and move this rectangle to mouse cordinates (Rectangle_MouseMove) and stop listening at (Rectangle_MouseLeftButtonUp).

Now, i have to add resize feature in this Rectangle. I wish to achieve this using Thumb, but i am unable to achieve this.

can someone please help me out with this. Thanks in advance.

1

1 Answers

0
votes

Adding all this reusable functionality directly to the objects seems a bit wasteful.

Why not just use a behaviour like this one? That's the sort of thing they are really good for. They are also decorated with handles etc.