Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Recalculating Transformation
Message
From
10/02/2009 15:47:16
 
 
General information
Forum:
ASP.NET
Category:
Windows Presentation Foundation (WPF)
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01380254
Message ID:
01380680
Views:
31
>UPDATE : Solved (at least to my satisfaction)

Viv, Viv, Viv ... you should know the rules around here by now. <g> We all want to know *how* you solved it.

~~Bonnie



>Hi,
>Here's a simple form with nested canvasses:
<Window x:Class="WpfApplication1.Window14"
>    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
>    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
>    Title="Window14" Height="400" Width="700">
>    <Canvas x:Name="MainCanvas">
>        <Canvas  Height="200" Width="200" Canvas.Top="50" Canvas.Left="100" Background="Blue">
>            <Canvas.RenderTransform>
>                <RotateTransform Angle="25"></RotateTransform>
>            </Canvas.RenderTransform>
>            <Canvas  Height="140" Width="140" Canvas.Top="30" Canvas.Left="30" Background="Red" MouseDown="Inner_MouseDown">
>                <Canvas.RenderTransform>
>                    <TransformGroup>
>                        <RotateTransform Angle="10"/>
>                    </TransformGroup>
>                </Canvas.RenderTransform>
>                <Canvas x:Name="Inner" Height="80" Width="80" Canvas.Left="60" Canvas.Top="20" Background="Yellow" MouseDown="Inner_MouseDown">
>                    <Canvas.RenderTransform>
>                        <TransformGroup>
>                            <RotateTransform Angle="40"></RotateTransform>
>                        </TransformGroup>
>                    </Canvas.RenderTransform>
>                    <TextBlock Canvas.Top="20" Canvas.Left="20" FontSize="20">Hello</TextBlock>
>                </Canvas>
>            </Canvas>
>        </Canvas>
>        <Canvas x:Name="Target" Width="200" Height="200" Canvas.Top="50" Canvas.Left="400" Background="PaleGreen">
>            <Canvas.RenderTransform>
>                <RotateTransform Angle="10" />
>            </Canvas.RenderTransform>
>        </Canvas>
>    </Canvas>
></Window>
>As an example when the user drags the canvas named "Inner" to the canvas named "Target" I want to switch the parent of "Inner" to match. Here's simple code to simulate:
private void Inner_MouseDown(object sender, MouseButtonEventArgs e)
>        {
>            Canvas parent = (Canvas) VisualTreeHelper.GetParent(Inner);
>            parent.Children.Remove(Inner);
>            Target.Children.Add(Inner);
>        }
However after the operation I want Inner to be displayed at the same overall rotation. What is the most elegant way of re-calculating the new rotation to be applied to "Inner"? (FWIW in practice there will be other transformations applied to the canvas so I guess I need to work with the matrix of a TransformGroup rather than a RotateTransform
>
>UPDATE : Solved (at least to my satisfaction)
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform