我来这里是因为我被这个非常烦人的问题困住了。我会尽量解释清楚。
我的 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/