Sunny

Sunny

  • NA
  • 2
  • 2.7k

rotate touch based needles of windows 8 clock app

May 15 2013 9:21 AM
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 dnt know how this is happning. How can i solve this issue. Please  anyone can  let me know.

Xaml code is :-

 <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:-

   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;
        }