简体   繁体   English

通过本地数据库创建的ObservableCollection <>绑定WP7应用程序中的AutocompleteBox

[英]Binding AutocompleteBox in WP7 Application from an ObservableCollection<>, created by a Local Database

I create an ObservableCollection<> using an query LinQ from a local database DB .sdf, then I bound the autocompleteBox (Silverlight Toolkit August 2011) with my ObservableCollection<> but this is very slow to load my elements. 我使用来自本地数据库DB .sdf的查询LinQ创建了一个ObservableCollection <>,然后将我的ObservableCollection <>绑定了autocompleteBox(Silverlight Toolkit,2011年8月),但这加载元素非常慢。

<toolkit:AutoCompleteBox ItemsSource="{Binding DSTAITEMS}" ValueMemberBinding="{Binding DESSTA}"  HorizontalAlignment="Left" Margin="69,67,0,0" Name="autoCompleteBoxPartenza" VerticalAlignment="Top"  Text="Stazione di partenza" Foreground="Gray"  Width="295" MouseEnter="autoCompleteBoxPartenza_MouseEnter">
            <toolkit:AutoCompleteBox.ItemTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding DESSTA}"></TextBlock>
                </DataTemplate>
            </toolkit:AutoCompleteBox.ItemTemplate>
        </toolkit:AutoCompleteBox>

The ObservableCollection<> in my code cs: 我的代码cs中的ObservableCollection <>:

 var elements= from r in myDB.stazioni select r;
        DSTAITEMS = new ObservableCollection<DSTA>(elements);

I've found that the auto-populate via ItemsSource can have some lag to it for large DBs. 我发现对于大型数据库,通过ItemsSource自动填充可能会有些滞后。

another method you want to look into would be to create the list first by populating based on a small primary key and using the C# to populate the text to the screen directly as it becomes visible or a focal point. 您要查看的另一种方法是先创建一个列表,方法是基于一个小的主键进行填充,然后使用C#将文本变为可见或焦点时直接将其填充到屏幕上。

For instance, I have to search a massive database of over 80,000 entities with over 9 different properties. 例如,我必须搜索包含8个以上具有9个不同属性的实体的庞大数据库。 when i do a search, I simply load the list based on the number of primary keys associated with entities that match the search parameters. 当我进行搜索时,我只是根据与匹配搜索参数的实体相关联的主键的数量加载列表。 the list usually loads within milliseconds and the length of time is solely based on the time to search the number of emlemets as opposed to loading their content. 该列表通常在几毫秒内加载,并且时间长短仅基于搜索Emlemet数量而不是加载其内容的时间。 Then, as the search is pressed, the search method loads a method to populate the first three elements. 然后,当按下搜索键时,搜索方法将加载一个用于填充前三个元素的方法。 As the users scrolls through the search results, each item's text and description is quickly populated as the user scrolls based on a finder method, as opposed to all at once. 当用户滚动搜索结果时,与基于一次查找的方法(而不是一次全部)相对,用户快速滚动查找每个项目的文本和说明。 As you can imagine a large search result - would take bloody ages to resolve otherwise. 您可以想象一个大的搜索结果-可能需要花很多时间才能解决。 you could also input a simple loading animation while the search content loads EVERYTHING if you didn't want to load "on the fly" This is also a dead useful approach when loading local images from text stored in the DB or attempting to load online data/images from a string in the DB. 如果您不想“即时”加载,也可以在搜索内容全部加载时输入一个简单的加载动画,这在从数据库中存储的文本加载本地图像或尝试加载在线数据时也是一种非常有用的方法/ images来自数据库中的字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM