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

╄→尐↘猪︶ㄣ 提交于 2019-12-12 03:34:43

问题


I get the following error:

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

when running the following line of javascript in my UWP App:

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

or

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

API Reference, Handle app activation Doc


回答1:


Windows.Ui.Xaml and the docs you linked aren't relevant for HTML/JavaScript apps. Windows.UI.Xaml is used only in Xaml apps.

To call activate You need a Windows.UI.Core.CoreWindow object, but Windows.UI.Core.CoreWindow itself is logically a class not an object

You need to create or acquire an instance of the class to call activate. To get such an object call CoreWindow's static method getForCurrentThread

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

That said, what problem are you actually trying to solve? Why are you calling this? Initial window activation in JavaScript apps is handled by framework code not called explicitly by app code. Unless you're managing multiple CoreWindows in your app, attempts to activate the window will depend on it already being active: you can't force your window on the user.



来源:https://stackoverflow.com/questions/42470746/javascript-runtime-error-unable-to-get-property-activate-of-undefined-or-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!