2012-07-18 4 views
0

나는 Windows 용 라이브 캔들 응용 프로그램을 만들고 있어요. 휴대 전화의 방향이 바뀌면 프레임의 방향을 변경하고 싶습니다. 이렇게 할 수 없습니다. 다음 코드를 사용하고 있습니다. : -애니메이션 있음 Wp7

namespace sdkSimpleMotionCS 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
    Motion motion; 

    // Constructor 
    public MainPage() 
    { 
     InitializeComponent(); 
    } 

    protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) 
    { 
     // Check to see if the Motion API is supported on the device. 
     if (!Motion.IsSupported) 
     { 
      MessageBox.Show("the Motion API is not supported on this device."); 
      return; 
     } 

     // If the Motion object is null, initialize it and add a CurrentValueChanged 
     // event handler. 
     if (motion == null) 
     { 
      motion = new Motion(); 
      motion.TimeBetweenUpdates = TimeSpan.FromMilliseconds(20); 
      motion.CurrentValueChanged += new EventHandler<SensorReadingEventArgs<MotionReading>>(motion_CurrentValueChanged); 
     } 

     // Try to start the Motion API. 
     try 
     { 
      motion.Start(); 
     } 
     catch (Exception) 
     { 
      MessageBox.Show("unable to start the Motion API."); 
     } 
    } 

    void motion_CurrentValueChanged(object sender, SensorReadingEventArgs<MotionReading> e) 
    { 
     // This event arrives on a background thread. Use BeginInvoke to call 
     // CurrentValueChanged on the UI thread. 
     Dispatcher.BeginInvoke(() => CurrentValueChanged(e.SensorReading)); 
    } 
    private void CurrentValueChanged(MotionReading e) 
    { 
     if (motion.IsDataValid) 
     { 
      // Show the numeric values for attitude 
      yawTextBlock.Text = "YAW: " + MathHelper.ToDegrees(e.Attitude.Yaw).ToString("0") + "°"; 
      pitchTextBlock.Text = "PITCH: " + MathHelper.ToDegrees(e.Attitude.Pitch).ToString("0") + "°"; 
      rollTextBlock.Text = "ROLL: " + MathHelper.ToDegrees(e.Attitude.Roll).ToString("0") + "°"; 

      // Set the Angle of the triangle RenderTransforms to the attitude of the device 
      ((RotateTransform)yawtriangle.RenderTransform).Angle = MathHelper.ToDegrees(e.Attitude.Yaw); 
      ((RotateTransform)pitchtriangle.RenderTransform).Angle = MathHelper.ToDegrees(e.Attitude.Pitch); 
      ((RotateTransform)rolltriangle.RenderTransform).Angle = MathHelper.ToDegrees(e.Attitude.Roll); 

      // Show the numeric values for acceleration 
      xTextBlock.Text = "X: " + e.DeviceAcceleration.X.ToString("0.00"); 
      yTextBlock.Text = "Y: " + e.DeviceAcceleration.Y.ToString("0.00"); 
      zTextBlock.Text = "Z: " + e.DeviceAcceleration.Z.ToString("0.00"); 

      // Show the acceleration values graphically 
      xLine.X2 = xLine.X1 + e.DeviceAcceleration.X * 100; 
      yLine.Y2 = yLine.Y1 - e.DeviceAcceleration.Y * 100; 
      zLine.X2 = zLine.X1 - e.DeviceAcceleration.Z * 50; 
      zLine.Y2 = zLine.Y1 + e.DeviceAcceleration.Z * 50; 
     } 
    } 
    } 
} 

모션 개념을 사용하고 있습니다.

답변