duccom
duccom

Reputation: 134

WPF performance issue when trying to update listbox real-time based on user input

I'm new in Windows Phone development and i'm trying to develop a dictionary app. I have a textbox to allow user input the word and a listbox to show all words which match the user input in real-time, so I'm used the textchanged event as below:

private void searchTextBox_TextChanged(object sender, TextChangedEventArgs e)
    {
            wordNeedToDefine = searchTextBox.Text;
            if (!(wordNeedToDefine == null || wordNeedToDefine.Equals("")))
            {
                var items = (from words in wordAndIndexList where words[0].StartsWith(wordNeedToDefine) select words[0]);                    
            }
            this.Dispatcher.BeginInvoke(() =>
            {
                wordsListBox.ItemsSource = items;
            });
    }

Everything is working fine but there are issues about performance, it's laggy when user input the text and listbox update the items. Can someone tell me what i need to do to increase the performance. I'm also trying the AutoCompleteBox but it's have same problem. Thanks in advance.

Upvotes: 0

Views: 222

Answers (1)

Matt Lacey
Matt Lacey

Reputation: 65556

You'll get better performance if you use a CollectionViewSource to do the filtering and the more characters you have to filter will make it faster. i.e. Only start filtering once the user has entered at least 3 characters.

Upvotes: 1

Related Questions