简体   繁体   中英

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.

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

 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.

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.

For instance, I have to search a massive database of over 80,000 entities with over 9 different properties. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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