我正在尝试使用Windows Phone 8上的NFC(邻近)API创建应用程序。当我从documentation复制示例代码时,出现以下编译错误...
error CS0103: The name 'Window' does not exist in the current context ...
这个错误遍布互联网,常见的解决方案似乎只适用于本机(或C ++)代码。但是文档说它适用于托管代码或本机代码。如何让我的托管代码中的示例工作?
答案 0 :(得分:1)
要获得对有效Windows.UI.Core.CoreDispatcher
对象的访问权限,您只需申请Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher
。
原始示例代码
// Write a message to MessageBlock on the UI thread.
private Windows.UI.Core.CoreDispatcher messageDispatcher =
Window.Current.CoreWindow.Dispatcher;
更正后的代码
// Write a message to MessageBlock on the UI thread.
private Windows.UI.Core.CoreDispatcher dispatcher =
Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher;
一个小小的变化使所有的例子都有效!享受。