Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Recalculating Transformation
Message
De
09/02/2009 07:26:40
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Windows Presentation Foundation (WPF)
Titre:
Recalculating Transformation
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Divers
Thread ID:
01380254
Message ID:
01380254
Vues:
79
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)
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform