elecman
Topic Author
Posts: 90
Joined: 20 Jul 2014, 04:28

RenderTransformOrigin does not work with grouped shapes

07 Feb 2015, 06:34

When shapes are grouped together (tree structure), setting RenderTransformOrigin on the parent has no effect.

Take for example the code below (exported from InkScape):
<Canvas Name="blueGroup">
  <Rectangle xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Canvas.Left="256.90518" Canvas.Top="775.85822" Width="241.09563" Height="138.33356" Name="blueLeft" Fill="#FF0000FF" StrokeThickness="0.5" Stroke="#FF000000" StrokeMiterLimit="4"/>
  <Rectangle xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Canvas.Left="790.47748" Canvas.Top="653.33423" Width="158.09549" Height="268.76233" Name="blueRight" Fill="#FF0000FF" StrokeThickness="0.5" Stroke="#FF000000" StrokeMiterLimit="4"/>
</Canvas>
Changing
<Canvas Name="blueGroup">
to
<Canvas Name="blueGroup" RenderTransformOrigin="0.5,0.5">
has no effect on the way the group of objects is rotated.

Adding this in code has no effect either:
square = root.FindName<UIElement>("blueGroup");
square.SetRenderTransformOrigin(new Point(0.5f, 0.5f));
 
User avatar
jsantos
Site Admin
Posts: 2900
Joined: 20 Jan 2012, 17:18
Contact:

Re: RenderTransformOrigin does not work with grouped shapes

07 Feb 2015, 15:29

The important fact here, is that RenderTransformOrigin is relative to the bounds of the control being applied to. In your example, you are setting that property in a Canvas, whose size fill the entire screen. So, (0.5,0.5) means the center of the screen.

If I change it this way (manually limiting the size of the parent canvas) I am getting the result you want:
<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  
 <Canvas Name="blueGroup" RenderTransformOrigin="0.5,0.5" Width="241" Height="268">
 
     <Canvas.RenderTransform>
        <RotateTransform Angle="10"/>
    </Canvas.RenderTransform>
 
 
  <Rectangle Width="241.09563" Height="138.33356" Name="blueLeft" Fill="#FF0000FF" StrokeThickness="0.5" Stroke="#FF000000" StrokeMiterLimit="4"/>
  <Rectangle Width="158.09549" Height="268.76233" Name="blueRight" Fill="#FF0000FF" StrokeThickness="0.5" Stroke="#FF000000" StrokeMiterLimit="4"/>
</Canvas>

</Page>
 
elecman
Topic Author
Posts: 90
Joined: 20 Jul 2014, 04:28

Re: RenderTransformOrigin does not work with grouped shapes

08 Feb 2015, 01:53

Thanks, setting the width and height of the canvas solves the problem, although I have yet to find a formula which converts the InkScape rotation center coordinates to RenderTransformOrigin, With, and Height values which give the same result.

Edit:
I found that the ViewerSvg svg to xaml converer correctly converts the Inkscape rotation center to the RenderTransformOrigin format.

Who is online

Users browsing this forum: Bing [Bot] and 0 guests