1

I'm implementing an application for Windows 8. It will search a quite large number of data from xml.

So for now I'm using a text box and list view to show the search results, but when i use the textbox event TextChanged is slows down the typeing, because it executes a new search for each letter typed.

So the question is, how to in metro / modern ui make a delay, to trigger the event after few letters are typed, not one.

Avangar
  • 236
  • 1
  • 4
  • 12

3 Answers3

2

You are discouraged from running anything that might bog down the UI as a synchronous task. Try running it as a background task which updates the UI on completion. See Background Task and TimeTrigger for more information. On task completion use the Core Dispatcher to update the UI. Core Dispatcher example

Community
  • 1
  • 1
N_A
  • 19,799
  • 4
  • 52
  • 98
  • Excellent! This is what I needed. I think i will go with this and the charm, also it will be useful for the rest of the application. Big thanks! Sadly I can't accept two answers :( – Avangar Sep 11 '12 at 07:05
  • Can't I have to have 15 reputation to do that. I sill miss 10. – Avangar Sep 12 '12 at 06:51
0

Why not use the "Leave" event instead of the text changed event of a text box? Would make it a lot smoother and would be when the user has finished their input inside the text box.

LukeHennerley
  • 6,344
  • 1
  • 32
  • 50
  • It more intuitive to just type, type & leave won't do. Also I want some sort suggestions when the user starts typing. – Avangar Sep 11 '12 at 07:18
0

You should not create your own Search experience. You should hook into the SearchPane and handle it there.

SearchPane searchPane = SearchPane.GetForCurrentView();
searchPane.QuerySubmitted += searchPane_QuerySubmitted;
searchPane.SuggestionsRequested += searchPane_SuggestionsRequested;

You can then handle the events as necessary in the handlers. If you are providing suggestions and you have a slow running process that will by async, you msut get a deferral.

void searchPane_SuggestionsRequested(SearchPane sender, SearchPaneSuggestionsRequestedEventArgs args)
{
    var deferral = args.Request.GetDeferral();
    // do real time type ahead here
    deferral.Complete();
}

void searchPane_QuerySubmitted(SearchPane sender, SearchPaneQuerySubmittedEventArgs args)
{
    // complete search here
}
Jeff Brand
  • 5,623
  • 1
  • 23
  • 22
  • Okay this works way better, kinda sad that it has to go through charm and can't to this with a normal textbox. But it will do. Thanks a lot for help! – Avangar Sep 11 '12 at 07:00
  • Could you update this with the new recommendations involving the `SearchBox` control? http://msdn.microsoft.com/en-us/library/windows/apps/hh465233.aspx – N_A Jun 01 '14 at 18:46