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);
            }
        }
  •   @tfsbuck thanks
  •   @densto @VSTS see email. one just timed out but that causing the other one that was waiting got picked up directly
  •   @VSTS did you send all your build agents already for weekend?
  •   @tfsbuck already made a issue https://t.co/u0EcaMewlV
  •   @tfsbuck back again :) you guys updated tf-cli today from .11 to .13 and now getting this error when try to publish… https://t.co/GLMVwL7HDZ
  •   @jpaternotte Soort zoekt soort! Past goed tussen de andere 149 clowns
  •   @sandeepchads @VSTS in the vsts sdk they are already visible; just returning 401
  •   RT @msbotframework: LUIS and the Azure Bot Service have just hit GA! 🎉 https://t.co/QVttVKrSWe
  •   @sandeepchads @VSTS Integration with my activity feed. Are the apis already open?
  •   @tfsbuck nice i had hard time to find the reproduction path. they also fixed my issue with publishing extension. new build task coming soon!