c# - 如何在全景 View 中的列表框中快速加载数据?

标签 c# .net xaml windows-phone panorama-control

我来这里是因为我被这个非常烦人的问题困住了。我会尽量解释清楚。

我的 Windows Phone xaml 页面上有一个 Panorama 控件,其中包含多个 PanoramaItem。在每个 PanoramaItem 中都有一个列表框,如本例所示:

<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>

我在后台从这样的数据库中提取数据:

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);
    }
}

我的问题是,当我导航到此页面时,加载数据需要花费太多时间,而且我数据库中的品牌(三星、lg、东芝...)不止这些。因此,加载需要 15 秒或更长时间,我的 UI 会卡住,有时还会崩溃。

我怎样才能让它加载得更快?我读过有关增量加载的内容,但我不知道如何让它与我的几个列表框一起使用。

非常感谢您的宝贵时间!

级别:初级。

最佳答案

您可能希望首先确保您的数据呈现为 Ilist 而不是 Ienumerable,以便使用数据虚拟化。添加“.ToList();”。

上下文.Samsung.Select(x => x.Model).ToList();

关于c# - 如何在全景 View 中的列表框中快速加载数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8485823/

相关文章:

c# - 如何检查Azure函数是否在本地环境中运行? `RoleEnvironment` 无法在 Azure Functions 中运行

c# - 当绑定(bind)到 WPF DataGrid 时,包装的 ObservableCollection<T> 抛出 `' EditItem' is not allowed for this view`

c# - Azure:监听非默认端口会导致访问被拒绝

c# - 如何在 C# 中使字段仅调试?

WPF - 全局添加 xaml 命名空间声明

c# - Controller 中有两种方法时的 API 和 OData 行为

c# - 在多个 C# 类之间共享属性

c# - 如何使用linq在where子句中设置条件过滤器?

c# - Windows Phone 8.1 如何以编程方式创建具有指定模板的磁贴

c# - WPF/MVVM - 检查基于字符串匹配的 MenuItem