我想用 ProximityDevice
在我的应用程序。我若为外地或在构造函数中,像这样的:
I want to use ProximityDevice
in my application. If I declare it as field or in the constructor, like this:
public partial class MainPage : PhoneApplicationPage {
// Constructor
public ProximityDevice device;
public MainPage() {
InitializeComponent();
device = ProximityDevice.GetDefault();
}
}
或这样的:
public partial class MainPage : PhoneApplicationPage {
// Constructor
public MainPage() {
InitializeComponent();
public ProximityDevice device = ProximityDevice.GetDefault();
}
}
我收到
A first chance exception of type 'System.UnauthorizedAccessException' occurred in SecurityClient.DLL
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.ni.dll
A first chance exception of type 'System.Reflection.TargetInvocationException' occurred in Microsoft.Phone.ni.dll
如果我把它声明为静态code使没有问题:
public partial class MainPage : PhoneApplicationPage {
// Constructor
public static ProximityDevice device = ProximityDevice.GetDefault();
public MainPage() {
InitializeComponent();
}
}
如何解决这个问题?
How to fix that problem?
请确保您添加的ID_CAP_PROXIMITY能力,你的应用程序清单。
Make sure you added the ID_CAP_PROXIMITY capability to your application manifest.