Search code examples
c#windows-8charms-bar

Windows 8 App, insert text into Search charm?


The use case I would like to enable is:

  1. User highlights some text in my app.
  2. User clicks Search charm.
  3. Search charm is populated by highlighted text.
  4. User clicks on Bing app, which, because of Search charm magic, automatically shows results for text in step 1.

So the only work from my app's side is to populate the Search charm box with some text. Has anyone found a way to do this yet? Or has anyone found that this can't be done?

Thank you in advance for any advice, and please let me know if I can make this question more clear! :)


Solution

  • This code will set the default search text:

    Windows.ApplicationModel.Search.SearchPane searchPane =
         Windows.ApplicationModel.Search.SearchPane.GetForCurrentView();
    searchPane.TrySetQueryText("default text");
    

    You'll just need to wire it up to whatever 'text selection' logic is part of your app.