question

BitSmithy-4663 avatar image
0 Votes"
BitSmithy-4663 asked NicoZhu-MSFT edited

TranslateTransform and RotateTransform together in UIElement

Hello,



TextBlock tbl = new TextBlock();

If I set

         RotateTransform rotateTransform = new RotateTransform();
         tbl.RenderTransform = rotateTransform;

I can rotate the TextBlock


If I set

 TranslateTransform moveTransform = new TranslateTransform();
 tbl.RenderTransform = moveTransform;

I can move TextBlock using mouse (here is more code needed).


But what if I want to have possibility to rotate object and move it using mouse in the same time?
Note: I must do it in code behind.

windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered NicoZhu-MSFT edited

TranslateTransform and RotateTransform together in UIElement



Hello, Welcome to Micorosoft Q&A,


For your scenario, you could use TransformGroup to Integrate TranslateTransform and RotateTransform together.


 var transforms = new TransformGroup();
 var rotateTransform = new RotateTransform();
 var moveTransform = new TranslateTransform();
    
 transforms.Children.Add(rotateTransform);
 transforms.Children.Add(moveTransform);
    
 // Set the render transform on the rect
 tb1.RenderTransform = transforms;


If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.