arjacsoh
arjacsoh

Reputation: 9242

Group items on a Canvas

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?

Upvotes: 4

Views: 4448

Answers (2)

Y.Yanavichus
Y.Yanavichus

Reputation: 2417

If you don't want to add another layout panels try to apply the same transform to all elements you want to move, it's not so heavy solution.

Upvotes: 1

Jay
Jay

Reputation: 57959

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.

Upvotes: 2

Related Questions