3

I'm here because I'm stuck on this very annoying problem. I will try to explain as clear as I can.

I have a Panorama control on my Windows Phone xaml page, with several PanoramaItems. Inside each PanoramaItem there is a Listbox like in this example:

<controls:Panorama ItemsSource="{Binding ContextCollection}" Title="Choose your model" x:Name="PanoramaAdd">
    <controls:PanoramaItem Header="Samsung">
        <Grid>
            <ListBox height="300"  Width="300" Name="Samsung_LBX"/>
        </Grid>
    </controls:PanoramaItem>

    <controls:PanoramaItem Header="LG">
        <Grid>
            <ListBox height="300"  Width="300" Name="LG_LBX"/>
        </Grid>
    </controls:PanoramaItem>

    <controls:PanoramaItem Header="Toshiba">
        <Grid>
            <ListBox height="300"  Width="300" Name="Toshiba_LBX"/>
        </Grid>
    </controls:PanoramaItem>

I pull my data from a database like this in my back office:

public ModelAdd()
{
    InitializeComponent();
    using (var _Context = new MyDataContext("Data Source=appdata:/DataAccessLayer.sdf;Mode=Read Only"))
    {
        //pull from my table Samsung all models of Samsung  in my Listbox                 
        Samsung_LBX.ItemsSource = _Context.Samsung.Select(x => x.Model);

        //pull from my table LG all models of LG in my Listbox
        LG_LBX.ItemsSource = _Context.LG.Select(x => x.Model);

        //pull from my table Toshiba all models of Toshiba  in my Listbox
        Toshiba.ItemsSource = _Context.Toshiba.Select(x => x.Model);
    }
}

My problem is that when I navigate to this page, the data takes too much time to load and there's more than those brands (samsung, lg, toshiba...) that I have in my database. So, it take 15s or more to load, my UI freezes, and sometimes it crashes.

How can I make this to load faster? I have read about incremental loading but I don't know how to make it work with my several listboxes.

Thank you very much for your time!

Level: Beginner.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Linus
  • 45
  • 4

1 Answers1

0

You might want to start by making sure your data is presented as a Ilist instead as a Ienumerable so data virtualization is used. Add '.ToList();'.

Context.Samsung.Select(x => x.Model).ToList();

invalidusername
  • 912
  • 9
  • 26
  • Ok thats a start ! thanks, i did that but not much difference through. – Linus Dec 13 '11 at 12:48
  • Maybe you can show us how you populate/create MyDataContext. The problem is probably within that specific piece of code. – invalidusername Dec 13 '11 at 14:06
  • I just used the "SQL Server Compact Toolbox" to generate the Datacontext with the option "Add Windows Phone DataContext to the Current Project" – Linus Dec 13 '11 at 16:11
  • Maybe you want to load the data in a BackgroundWorker Thread to a temporary collection and at the end switch back to the UI Thread and assign the values to the listbox. I assume that the SQL CE is causing the delay. You could also try using the Performance Analyzer for Windows Phone to figure out which methods are running so long. – invalidusername Dec 13 '11 at 18:16