- Sep 11, 2012
- 41
- 0
- 0
Hi,
I'm currently writing a dictionary app using databound app template. My database is a sqlite database with more than 300.000 rows. Here is my code to store loaded database.
And I use a TextBlock to display wordString and a phoneTextBox to search words.
And here is the code for searching:
The problem is when I do a search, it takes to long to response.
Could you please give me a hint to accelerate my search? Could I create an indexer on ObservableCollection?
Thanks in advance.
I'm currently writing a dictionary app using databound app template. My database is a sqlite database with more than 300.000 rows. Here is my code to store loaded database.
Code:
public class Word
{
[PrimaryKey]
public int Id { get; set; }
public string WordString { get; set; }
public string Content { get; set; }
}
public class WordList
{
public ObservableCollection<Word> Items { get; set; }
public WordList()
{
Items = new ObservableCollection<Word>();
}
}
public class ViewModel {
//....
public async void LoadData()
{
var query = DB.Table<Word>();
var result = await query.ToListAsync();
foreach (Word w in result)
{
WList.Items.Add( new Word()
{
Id = w.Id,
WordString = w.WordString,
Content = w.Content
});
}
IsDataLoaded = true;
}
}
And I use a TextBlock to display wordString and a phoneTextBox to search words.
Code:
<toolkit:PhoneTextBox Hint="Search"
TextChanged="SearchBox_TextChanged"
Name="SearchBox"
VerticalAlignment="Top" />
.....
<TextBlock Text="{Binding WordString}"
FontSize="30"
TextWrapping="Wrap"
VerticalAlignment="Center"
Margin="20,0,0,0"
Foreground="Black"
FontWeight="Bold"
Grid.Row="0" />
And here is the code for searching:
Code:
....
private void SearchBox_TextChanged(object sender, TextChangedEventArgs e) {
IList<Word> results = App.ViewModel.WList.Items
.Where(tb =>tb.WordString.StartWith(SearchBox.Text))
.ToList();
ListBox1.ItemsSource = results;}
The problem is when I do a search, it takes to long to response.
Could you please give me a hint to accelerate my search? Could I create an indexer on ObservableCollection?
Thanks in advance.