locked
ListBox Items sometimes not visible on app Resume

    Question

  • Hey,

    I have a winRT windowsphone 8.1 app in development and I've come across a strange problem sometimes.

    Basically, when my app loads, I pull items from an RSS using syndication feed, store to a data set which is binded to the listbox. This works perfectly.

    I can even hold the back button, terminate the app, then reload it and the items repopulate instantly (guessing the app automatically saves state? I didn't program this in) but occasionally, the listbox is empty. Or so I think, turns out the items are still loaded; I tap the blank screen and an article shows up, I can still even scroll up and down this blank space, tap other blank areas and different articles from that feed load. So clearly the listbox is still populated, Just not visible.

    Does anyone know what causes this? Any advice on what I need to be doing here? Can provide code if required.

    Wednesday, January 21, 2015 2:20 PM

Answers

  • Ive managed to actually fix this problem properly:

    SOLUTION: Do not populate and bind listbox in "onnvaigatedto"; it needs to be done after the page has loaded so add:

    this.Loaded += Page_Loaded;

    to the constructor

    and do the loading and binding in here:

    void Page_Loaded(object sender, RoutedEventArgs e)
            {
                // do binding and such
            }

    • Marked as answer by kmrastegar Saturday, January 31, 2015 12:38 AM
    Saturday, January 31, 2015 12:38 AM

All replies

  • Hi kmrastegar,

    Looks like the items are successfully loaded but they do not shown on UI, could you check if items' visibility are set to hidden? I have seen a similar post that some of the items are automatically set to hidden after the app binding, but not sure if you have the same issue.

    --James


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, January 22, 2015 2:27 AM
    Moderator
  • The items are never set to collapsed; the entire listbox starts off as collapsed until the content is loaded, and then it fades to visible, so I know that cant be the problem as if the listbox was still collapsed, I wouldn't be able to tap anything. It happens so very rarely Im led to believe its not something ive strictly coded in, but maybe something im forgetting to do on quitting/resuming the app? Like I said, most times I can shut down the app and reopen it fine, I can see all the content, but every now and then, the listbox will be invisible, but still tappable/triggerable.
    Saturday, January 24, 2015 12:57 AM
  • Yeah I'm at a loss. It happens sometimes when I navigate away from the page to my settings, and then navigate back. For testing purposes I also set the following properties on the part of "onnavigatedto" method that handles navigating back from a page:

    ListBoxRss.Opacity = 1;

    ListBoxRss.Visibility = Visibility.Visible;

    And I still cant see the listbox (remember, it doesnt always happen. About 1 in 6 times it happens), but as I said i can still scroll and I can still tap these invisible elements and it still loads the relevant article. It's never happened in my Silverlight apps so I'm stumped. Really don't get whats going on :(


    • Edited by kmrastegar Sunday, January 25, 2015 12:01 PM clarity
    Sunday, January 25, 2015 12:00 PM
  • Alright so I worked out part of the problem. The reason it wasnt working on navigating back sometimes is that parts of the code for initialising the listBox resided in the constructor, and not "onnavigatedto". Moving the code into that method fixed the issue when navigating back pages.

    However, the problem still remains on physically closing the app (swiping it away in multitask view). When the app is loaded again, the listbox is blank, but operable (the feed is clearly loaded as selecting the blank screen opens articles). It seems that this doesnt occur if I change the "bypasscahceonretreive" property on the syndicatedfeed to "true", but if i set this that means the page will always bypasscache when navigated back to it, i dont want this (waste of quota) so i still need to fix that one.

    Im thinking i may need to implement proper resuming when the app is "closedbyuser"? So add an "onloaded" handler, and it the app was closed by user then just bypass the cache and itll probably work (again, not ideal, as id be happy for it to use the cache).

    Does this sound like the correct behaviour?

    EDIT:

    --------

    I had to do this. It worked, but wasnt ideal. So i bypassed cache on app first load and now it always shows up. weird.

    • Edited by kmrastegar Tuesday, January 27, 2015 9:19 AM answer
    • Marked as answer by kmrastegar Tuesday, January 27, 2015 9:19 AM
    • Unmarked as answer by kmrastegar Saturday, January 31, 2015 12:38 AM
    Monday, January 26, 2015 2:48 AM
  • Ive managed to actually fix this problem properly:

    SOLUTION: Do not populate and bind listbox in "onnvaigatedto"; it needs to be done after the page has loaded so add:

    this.Loaded += Page_Loaded;

    to the constructor

    and do the loading and binding in here:

    void Page_Loaded(object sender, RoutedEventArgs e)
            {
                // do binding and such
            }

    • Marked as answer by kmrastegar Saturday, January 31, 2015 12:38 AM
    Saturday, January 31, 2015 12:38 AM