1

I follow these steps

This app requires references to the assemblies containing the sensor APIs and the XNA Framework because accelerometer data is passed in the form of an XNA Framework Vector3 object. From the Project menu, click Add Reference…, select Microsoft.Devices.Sensors and Microsoft.Xna.Framework, and then click OK.

But why this error is coming Accelerometers is 'namespace' but is used like a 'type'

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Net;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Documents;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Animation;
 using System.Windows.Shapes;
 using Microsoft.Phone.Controls;
 using Microsoft.Devices.Sensors;
 using Microsoft.Xna.Framework;

 namespace Accelerometer
 {
   public partial class MainPage : PhoneApplicationPage
   {
    // Constructor
    Accelerometer accelerometer;


    public MainPage()
    {
        InitializeComponent();

        if (!Accelerometer.IsSupported)
        {
            // The device on which the application is running does not support
            // the accelerometer sensor. Alert the user and disable the
            // Start and Stop buttons.
            statusTextBlock.Text = "device does not support accelerometer";
            startButton.IsEnabled = false;
            stopButton.IsEnabled = false;
          }
       }
dcastro
  • 66,540
  • 21
  • 145
  • 155
askquestion
  • 171
  • 1
  • 14

1 Answers1

3

I think you want to use this Accelerometer class for windows phone but since your namespace is also Accelerometer, program gives an error. It checks the namespace name first.

You can change your namespace name something else or you can use full name of your Accelerometer class like;

if (!Microsoft.Devices.Sensors.Accelerometer.IsSupported)
{
   //
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
  • 2
    This is correct. With the `using` directives placed as above, the global namespace is search just before the namespaces of the `using` directives. And because his namespace `Accelerometer` is found in the former search, we never get to the search in `Microsoft.Devices.Sensors` where `Microsoft.Devices.Sensors.Accelerator` would have been found. Se [my post elsewhere](http://stackoverflow.com/a/16092975/1336654) for details. Your own code is incorrect. You don't use full name of the class as you claim, and the `IsSupported` property is `static`. – Jeppe Stig Nielsen Mar 04 '14 at 08:44
  • @JeppeStigNielsen Oh, you are right. Updated. Thank you. – Soner Gönül Mar 04 '14 at 08:48