0

I don't want to use the built in system for rotate that uses two fingers as I must rotate this with a single point.

I am trying to rotate a rectangle in a canvas. But for some reason the rectangle shakes, does extra turns. Anyone know whats wrong?

Does anyone know how I can do something like the wpf Translate point.

Point myPoint = control.TranslatePoint(point, parent)?

<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Canvas x:Name="myCanvas" MinHeight="400" MinWidth="400" >
        <Rectangle x:Name="Spinner" Fill="LightGray" Canvas.Left="100" Canvas.Top="100" Height="200" Width="200" 
                   ManipulationMode="All" 
                   ManipulationDelta="Spinner_ManipulationDelta"  >
            <Rectangle.RenderTransform>
                <CompositeTransform x:Name="myTransform" CenterX="100" CenterY="100" Rotation="0" />
            </Rectangle.RenderTransform>
        </Rectangle>
    </Canvas>
    <StackPanel Orientation="Horizontal" VerticalAlignment="Bottom" Margin="20" >
        <TextBlock Text="Speed (px per Millisecond): " />
        <TextBlock x:Name="SpeedX" ManipulationMode="None" Text="0"  />
        <TextBlock Text=",  " />
        <TextBlock x:Name="SpeedY" ManipulationMode="None" Text="0"/>
        <TextBlock Text="Point: " />
        <TextBlock x:Name="PointX" ManipulationMode="None" Text="0"  />
        <TextBlock Text=",  " />
        <TextBlock x:Name="PointY" ManipulationMode="None" Text="0"/>
    </StackPanel>
</Grid>
</Page>

The code behind is pretty simple

   private void Spinner_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        Point touch = e.Position; // Really want this point to be relative to the canvas 
        Point center = new Point(100, 100); // Really want the point relative to the canvas 

        double x = touch.X - center.Y;
        double y = center.Y - touch.Y; // Tried this reversed.. No difference

        double radians = Math.Atan2(y, x);

        myTransform.Rotation  += radians;

        // show the mouse position in the UI
        this.PointX.Text = touch.X.ToString();
        this.PointY.Text = touch.Y.ToString();
    }

By the way using code from SO Post

Haydn
  • 293
  • 1
  • 2
  • 13

0 Answers0