Binding stopped working


  • I have a metro style application and the ListView control has just stopped working.

    var userListView = WinJS.UI.getControl(document.getElementById("userListView"));
    userListView.dataSource = new WinJS.UI.ArrayDataSource(users);

    The users array has items in it, but I seem to have done something to my application that means these no longer get rendered on screen.

    So far, I have tried:

    - pasting in fresh copies of all the WinJS scripts in case I had mistakenly corrupted one
    - checked the javascript console window for errors and warnings (and even info) - nothing interesting in there
    - debugging and checking the value of users - it does have items inside this array
    - removing recent additions to the project
    - adding a new splitPage.html from the templates. This doesn't work either and uses binding in a similar way.
    - double checking for any additions to the global object that might cause a problem - can't see anything.
    - double checked that all the appropriate references are added to the project
    - created a new sln with a splitPage - this separate sln works fine.

    Help! What might I have done wrong?

    Sunday, November 27, 2011 7:03 PM

All replies

  • Hey Mo,

    I would make a copy of your project to save it, then start cutting pages, code and JS out until you find out what is causing the problem.  At some point you will have whittled this down to the equivalent of your new project with a split page.  At that point if it still fails you can use WinDiff to see what is different with the files you have left to spot the problem.


    Jeff Sanders (MSFT)
    Tuesday, November 29, 2011 3:07 PM
  • Is WinJS.UI.getControl returning a proper list view? If not then perhaps your markup was corrupted, or this code is being run before WinJS.UI.ProcessAll is completed. This function is async, so you should attempt to use your ListView after that promise completes... this kind of race condition is easy to introduce with an innocuous change.

    If the ListView control is there, then what is the type of the individual "user" object? If it is a simple JSON built object then it should work, if they are something that came in via WinMD (marshalled from a managed or native component). If it's WinMD then there's currently a Developer Preview bug where some WinMD object properties cannot be extended in JS, and thus cannot be made observable, and thus fail in databinding by the ListView’s rendering Template control. If that's the case I can give you some code to work around this problem.

    Senior Dev for Windows Phone Services

    Tuesday, November 29, 2011 7:30 PM