Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Group items on a Canvas

Tags:

c#

wpf

shapes

I am creating shapes on a wpf using a Canvas. I have created by C# code some Rectangles, each one of which is assigned with three circles and a TextBlock. I want now to make them move on the Canvas by a mouseEvent , in other words to drag them with the mouse and to move them on the Canvas. How is it possible to manipulate each Rectangle with the circles and the TextBlock as a compact group?

It is required, when the user clicks on the Rectangle to transfer it with its contents. However, the circles and the textBlock have their own coordinates, so if not grouped they stand still. How can I get over this?

like image 397
arjacsoh Avatar asked Oct 28 '25 00:10

arjacsoh


1 Answers

Put the rectangle and everything else in a grid or another canvas, as described in this related question of yours: Drawing circles on a Rectangle

This is basically a user control composed of the rectangles, circles, and textbox, and you just allow that whole user control to be moved around, rather than the constituent parts.

like image 135
Jay Avatar answered Oct 30 '25 16:10

Jay