Type to search in Windows 8

In het startscherm kan je gaan typen om te gaan zoeken in een applicatie. Dit gedrag is ook heel eenvoudig in je applicatie te realiseren, maar er zit een maar aan. De meest voor de handliggende oplossing op keydown van het core window het searchpane openen:

Window.Current.CoreWindow.KeyDown += CoreWindow_KeyDown;

void CoreWindow_KeyDown(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
{
      SearchPane.GetForCurrentView().Show();
}

 Echter zal je zien met deze oplossing dat je altijd de eerste toetsaanslag mist in de seearch query. Dit is onhandig. Best is om de event handler iets uit te breiden en zelf de eerste toetsenbord aanslag af te handelen:

void CoreWindow_KeyUp(Windows.UI.Core.CoreWindow sender, Windows.UI.Core.KeyEventArgs args)
        {

            if ((int)args.VirtualKey >= 48 && (int)args.VirtualKey <= 90)
            {
                string text = string.Empty;

                switch (args.VirtualKey)
                {
                    case Windows.System.VirtualKey.Number0:
                        text = "0";
                        break;
                    case Windows.System.VirtualKey.Number1:
                        text = "1";
                        break;
                    case Windows.System.VirtualKey.Number2:
                        text = "2";
                        break;
                    case Windows.System.VirtualKey.Number3:
                        text = "3";
                        break;
                    case Windows.System.VirtualKey.Number4:
                        text = "4";
                        break;
                    case Windows.System.VirtualKey.Number5:
                        text = "5";
                        break;
                    case Windows.System.VirtualKey.Number6:
                        text = "6";
                        break;
                    case Windows.System.VirtualKey.Number7:
                        text = "7";
                        break;
                    case Windows.System.VirtualKey.Number8:
                        text = "8";
                        break;
                    case Windows.System.VirtualKey.Number9:
                        text = "9";
                        break;
                    case Windows.System.VirtualKey.A:
                    case Windows.System.VirtualKey.B:
                    case Windows.System.VirtualKey.C:
                    case Windows.System.VirtualKey.D:
                    case Windows.System.VirtualKey.E:
                    case Windows.System.VirtualKey.F:
                    case Windows.System.VirtualKey.G:
                    case Windows.System.VirtualKey.H:
                    case Windows.System.VirtualKey.I:
                    case Windows.System.VirtualKey.J:
                    case Windows.System.VirtualKey.K:
                    case Windows.System.VirtualKey.L:
                    case Windows.System.VirtualKey.M:
                    case Windows.System.VirtualKey.N:
                    case Windows.System.VirtualKey.O:
                    case Windows.System.VirtualKey.P:
                    case Windows.System.VirtualKey.Q:
                    case Windows.System.VirtualKey.R:
                    case Windows.System.VirtualKey.S:
                    case Windows.System.VirtualKey.T:
                    case Windows.System.VirtualKey.U:
                    case Windows.System.VirtualKey.V:
                    case Windows.System.VirtualKey.W:
                    case Windows.System.VirtualKey.X:
                    case Windows.System.VirtualKey.Y:
                    case Windows.System.VirtualKey.Z:
                        text = args.VirtualKey.ToString().ToLower();
                        break;
                }


                if ((Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Shift) & Windows.UI.Core.CoreVirtualKeyStates.Down) == Windows.UI.Core.CoreVirtualKeyStates.Down ||
                    (Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.CapitalLock) & Windows.UI.Core.CoreVirtualKeyStates.Locked) == Windows.UI.Core.CoreVirtualKeyStates.Locked)
                {
                    text = text.ToUpper();
                }

                SearchPane.GetForCurrentView().Show(text);
                Frame.Navigate(typeof(SearchPageView), text);
            }
        }
  •   RT @windowsblog: Windows Template Studio 1.1 released! https://t.co/qCLpESAvnB
  •   @JenMsft and does sqrt(4) - 2 gives now the right awnser?
  •   @Alex_A_Simons any updates on that what more is happening ? (2/2)
  •   @Alex_A_Simons long time ago you said the mess between msa and aad's would be fixed; first step was block to create msa on aad account. (1/2
  •   First pullrequest for https://t.co/5lEHH630Io :)
  •   @qmatteoq whosdown is great alternative for whatapps and comes from the store
  •   @jvintzel only for windows 10 s users or can other surface users get it too?
  •   RT @JenMsft: O hi there @Spotify 😊 #Windows10 https://t.co/nlJUgM7vVG https://t.co/boah802WgZ
  •   RT @tvgrimbergen: Awesome! Just extended our @MicrosoftTeams bot. Provide natural language input to initiate a leave request powered by @Ni…
  •   @lancewmccarthy kind of sad :/