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);
            }
        }
  •   @MicrosoftHelps fixed it by reinstalling windows but thanks for following up
  •   @JenMsft should have log feedback before resetting windows... but was soo annoyed my pen was not working
  •   @JenMsft surface book with perf base. i reinstalled windows and problem is gone. nasty thing if multi touch doesnt… https://t.co/0vxuKMC6vv
  •   @JenMsft after i installed the FCU multitouch doesnt work. when uninstall driver and reboot it works till next reboot. heared it before?
  •   RT @ruudj: https://t.co/WWSQcFP45k
  •   @maarten_goet @we_are_inspark Nice congrats
  •   nice app showing all windows controls https://t.co/kogun2ws2P
  •   RT @windowsblog: New Map Control features in Windows 10 Fall Creators Update https://t.co/gTLqVAX8HO https://t.co/wuGGF6Yi3Q
  •   RT @LocalJoost: Rather loud explosion sounds at @davesmits #techdaysnl presentation. Who ever was asleep is definitely awake again now 😀
  •   RT @we_are_inspark: 'A Shared HoloLens experience' door @davesmits op @TechDaysNL. Volg zijn sessie over 30 min. in zaal G104-105. https://…