locked
Window.Current in a WinJS application RRS feed

  • Question

  • Hello,

    I have a Window Runtime Component that accesses the Window.Current object, to add an handler on the VisibilityChanged event.

    If I run that code in a C# Windows Store App, it runs perfectly (as soon as I do that in a method where the Window has been initialized).

    Unfortunately, I am unable to do that in a WinJS app. It breaks when I launch the app.

    Why ?

    Thanks !

    Thursday, December 20, 2012 1:12 PM

Answers

  • Hi ubikod,

    The Window.Current property you mentioned is a Xaml specific class property which cannot be used in Windows Store javascript application.

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.window.current.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

    For Windows Store html5 + js based app, it has different programing model for you to detect the layout changing (such as the orientation/ viewState changes). You can use the javascript "window.onresize" event to detect such change. You can create a simple "Split App" through Vs 2012 Windows Store javascript app template which contains the code for handling the window size/view state changing condition.

    And for your windows runtime library, if you want to make it works the same way in both .NET and javascript based windows store app, I think you can consider the following design:

    •  Instead of directly hook the event in your WinRT library's code, you can define some event on your WinRT component class (which will be used by .NET, C++ or HTML/js based windows store apps).
    •  And in the front-end windows store app (either C++, .NET or HTML/JS ones), you can register the window resize or layout changing event according to the programming mode of the specific language and fire the event exposed on the WinRT library component class (and pass in the necessary parameters via event arguments).


    Here is a freebook which is really good for getting family with windows store javascript programming:



    #Free ebook: Programming Windows 8 Apps with HTML, CSS, and JavaScript
    http://blogs.msdn.com/b/microsoft_press/archive/2012/10/29/free-ebook-programming-windows-8-apps-with-html-css-and-javascript.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Thursday, December 27, 2012 10:11 AM
    Monday, December 24, 2012 6:52 AM
    Moderator

All replies

  • Hi,

    Please have a debug with the component.

    #Quickstart: Debugging apps (JavaScript)

    http://msdn.microsoft.com/en-us/library/windows/apps/hh441474.aspx


    Roy
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, December 21, 2012 9:21 AM
  • Hi ubikod,

    The Window.Current property you mentioned is a Xaml specific class property which cannot be used in Windows Store javascript application.

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.window.current.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

    For Windows Store html5 + js based app, it has different programing model for you to detect the layout changing (such as the orientation/ viewState changes). You can use the javascript "window.onresize" event to detect such change. You can create a simple "Split App" through Vs 2012 Windows Store javascript app template which contains the code for handling the window size/view state changing condition.

    And for your windows runtime library, if you want to make it works the same way in both .NET and javascript based windows store app, I think you can consider the following design:

    •  Instead of directly hook the event in your WinRT library's code, you can define some event on your WinRT component class (which will be used by .NET, C++ or HTML/js based windows store apps).
    •  And in the front-end windows store app (either C++, .NET or HTML/JS ones), you can register the window resize or layout changing event according to the programming mode of the specific language and fire the event exposed on the WinRT library component class (and pass in the necessary parameters via event arguments).


    Here is a freebook which is really good for getting family with windows store javascript programming:



    #Free ebook: Programming Windows 8 Apps with HTML, CSS, and JavaScript
    http://blogs.msdn.com/b/microsoft_press/archive/2012/10/29/free-ebook-programming-windows-8-apps-with-html-css-and-javascript.aspx


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Song Tian Thursday, December 27, 2012 10:11 AM
    Monday, December 24, 2012 6:52 AM
    Moderator