Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
=> How to implement Touch based rotation with windows 8 app using C# and XAML

I have mine windows 8 analog clock app that perform Touchable task to move minutes and hour angle by single touch ,but it could not work properly. it seems to be did not find angle correctly . I had worked on Manupulation delta events of clock needle ( i.e Line ) . When I moved needles forward than 1st time it goes some points backward. I don't know how this is happning. Please anyone can let me know how can I solve this issue. Ma complete code is below.

XAML Code is :-

HTML
<Line Name="Hours" PointerEntered="ShowHand" PointerExited="ShowArrow" HorizontalAlignment="Center" VerticalAlignment="Center" X1="0" Y1="0" X2="0" Y2="-70" Stroke="Wheat" Margin="1,0,0,0" StrokeThickness="3" Grid.RowSpan="8" ManipulationDelta=" HourRight_ManipulationDelta" ManipulationMode="TranslateInertia,TranslateX,TranslateY">
            <Line.RenderTransform>
                <RotateTransform x:Name="HoursTransform" CenterX="0" CenterY="0" Angle="{Binding HourHandAngle}" />
            </Line.RenderTransform>
        </Line>

.cs Code is:-
C#
private void HourRight_ManipulationDelta(object sender, ManipulationDeltaRoutedEventArgs e)
    {
        var x = HoursTransform.CenterX - e.Position.X;
        var y = HoursTransform.CenterY - e.Position.Y;

        var angle = Math.Atan(y / x);
        var deltaAngle = Math.Atan((e.Delta.Translation.Y - y) / (x - e.Delta.Translation.X));

        this.HoursTransform.Angle += angle - deltaAngle;
    }

Kinds Regards in advance
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900