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

0

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

javascript
uwp
windows-store-apps
asked on Stack Overflow Feb 26, 2017 by jonhue • edited Feb 26, 2017 by jonhue

1 Answer

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.

answered on Stack Overflow Feb 28, 2017 by Rob Caplan - MSFT

User contributions licensed under CC BY-SA 3.0