JavaScript 运行时错误 : Unable to get property 'activate' of undefined or null reference

标签 javascript uwp windows-store-apps

我收到以下错误:

0x800a138f - JavaScript runtime error: Unable to get property 'activate' of undefined or null reference

在我的 UWP 应用程序中运行以下 JavaScript 行时:

Windows.UI.Xaml.Window.activate();
Windows.UI.Xaml.Window.current.activate();

Windows.UI.Core.CoreWindow.activate();

API Reference , Handle app activation Doc

最佳答案

Windows.Ui.Xaml 和您链接的文档与 HTML/JavaScript 应用程序无关。 Windows.UI.Xaml 仅在 Xaml 应用中使用。

要调用activate,您需要一个Windows.UI.Core.CoreWindow对象,但Windows.UI.Core.CoreWindow本身在逻辑上是一个类而不是对象

您需要创建或获取该类的实例才能调用 activate。要获取这样的对象,请调用 CoreWindow 的静态方法 getForCurrentThread

var window = Windows.UI.Core.CoreWindow.getForCurrentThread();
Window.activate();

也就是说,您实际上想解决什么问题?你为什么这么称呼? JavaScript 应用程序中的初始窗口激活由框架代码处理,而不是由应用程序代码显式调用。除非您在应用程序中管理多个 CoreWindows,否则尝试激活窗口将取决于它是否已处于事件状态:您不能强制用户使用窗口。

关于JavaScript 运行时错误 : Unable to get property 'activate' of undefined or null reference,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42470746/

相关文章:

c# - 如何在弹出对话框打开时禁用后台 GUI 交互

java - 是否可以在 Windows Phone 上的 C# 中运行 java 程序?

javascript - 菜单.asp javascript

c# - UWP C# ListView 返回被点击行的Id值

c# - 我如何处理自定义应用程序设置? Windows 10 UWP C#

全息镜头中的 C++ dll

c# - 单击按钮期间是否可以等待异步任务?

javascript - 如何在委托(delegate)的事件监听器中支持 stopPropagation

php - javascript 相当于数组的 php max

javascript - Mouseout 和 Mouseover 事件在 Chrome 39 中无法正常触发