Search code examples
c#.netxamlwindows-phonepanorama-control

How to load data fast on listboxes in Panorama View?


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.


Solution

  • 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();