Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
XML
<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;

private void Canvas_MouseLeftButtonDown(object sender,MouseButtonEventArgs e) {}
private void Canvas_MouseMove(object sender, MouseEventArgs e) {}
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 need the Rectangle Re-sizable and Movable functionalities.
Can u please provide me how to achieve the Rectangle Re-sizable and Movable functionalities.?


Thanks....
Posted
Updated 31-Dec-13 19:03pm
v3
Comments
Sergey Alexandrovich Kryukov 31-Dec-13 12:38pm    
You are moving in right direction, but what is your problem. You don't show this code. What have you tried so far?
—SA
[no name] 1-Jan-14 1:04am    
I Also need the Rectangle Re-sizable and Movable functionalities.
Can u please provide me how to achieve the Rectangle Re-sizable and Movable functionalities.?

Using mouse events is not the best way to move a rectangle in Silverlight.
I suggest you use linear animations - e.g. http://msdn.microsoft.com/en-us/library/cc189066%28v=vs.95%29.aspx[^].
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 1-Jan-14 1:41am    
You would be perfectly right if by "movable" OP meant animation. But it's pretty obvious that he means interactive changes, otherwise he would not consider mouse events (please see the question text again), so, animation information is not useful here.
—SA
[no name] 1-Jan-14 2:15am    
Hi and Happy New Year,
Abhinav gave me the link about how to handle rectangle event and its works good.
[no name] 1-Jan-14 2:13am    
Hey, Abhinav

I have go through your link and its works like charm. You have solved my drag and drop problem.

I also need some more help about how to make the Rectangle Resizable.
So Do you have any idea about resizing of rectangle object??

Thanks...
Sergey Alexandrovich Kryukov 1-Jan-14 2:28am    
I don't know what else you are missing. Please check up my answer. If it does not work by some reason, make a shortest possible code sample and add it to your question. Please read this: http://www.sscce.org.
—SA
As I say, you are probably quite close and only need to apply the logic of your scenarios or debug your code. From your words, I can see that your approach is quite correct, and I cannot see your code to find out where is the flaw.

The only useful piece of information you might have missed is the possibility to use hit testing capabilities in visual layer already developed for you in WPF. Please read this: http://msdn.microsoft.com/en-us/library/ms752097%28v=vs.110%29.aspx[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900