locked
Lazy-loading pivot too lazy? RRS feed

  • Question

  • Hi and pardon my noobishness (first app)

    I'm trying to lazy-load my model in a pivot event method like

            private async void Loading_Pivot(object sender, PivotItemEventArgs e)
            {
                Pivot pivot = (Pivot)sender;
                switch (pivot.SelectedIndex)
                {
                    case 0: App.ViewModel.currentStudent.messages = await dostuff1(); break;
                    case 1: App.ViewModel.currentStudent.sentMessages = await dostuff2(); break;
                    case 2: App.ViewModel.currentStudent.archivedMessages = await dostuff3(); break;
                    case 3: App.ViewModel.currentStudent.draftMessages = await dostuff4(); break;
                }   

            }

    but the list populated by the respective parts of the model remain empty on the page even debugging verifies the data get loaded. Apparently the list is being rendered before the data is there (or something needs to be done in order to tell the control the data has been loaded?). How is this kind of stuff usually done?

    Thanks in advance,

     Nik

    Tuesday, October 1, 2013 6:09 AM

All replies

  • This brief code snippet suggests that the pivot's information is populated only once, during load of the pivot itself, which occurs exactly one time during creation of the visual tree.  Even then, only the currently selectedindex (a single PivotItem) gets populated. 

    It sounds to me that what you really want is for the pivotitem to get populated when it gets loaded.  You should be using the Pivot.LoadingPivotItem event instead.

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.


    Tuesday, October 1, 2013 1:25 PM
  • Thanks for the reply, I am using the 

     <phone:Pivot Name="MessagePivot" LoadingPivotItem="Loading_Pivot">

     I understand your point about example projects, I'll be back with an isolated sample if there isn't anything obvious in the line above...

    Thanks,

      Nik

    Tuesday, October 1, 2013 3:00 PM
  • Just because it's loaded it doesn't mean it's selected.  :-)

    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Wednesday, October 2, 2013 12:31 PM