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 @VisualStudio: In this episode, we're joined by Kasey Uhlenhuth (@kuhlenhuth) who shows some of the refactoring features available in Vi…
  •   @VSTS problems with build queues atm?
  •   RT @donasarkar: Hi #WindowsInsiders we have released Build 17713 to the Fast ring! This build has several new features we think IT Pros wil…
  •   RT @maryjofoley: ICYMI, another Windows 10 on ARM PC is available: Lenovo Miix 630 ARM-based 2-in-1 Windows tablet goes on sale for $900 ht…
  •   the moment you have a meeting and skype for business protocol handller is lost again ...
  •   @LocalJoost Surface Go vanaf 27 augustus te bestellen?
  •   tnx @VistaHypotheken https://t.co/qFoQS6mQ63
  •   @gotheap based on the link i understand they should show up after a build as well? i only see them for the test on… https://t.co/XadwWJjIAM
  •   @panos_panay will the surface go with lte have gps? i need a new device to run my own app for navigation while flying around
  •   @aaronbjork @IoannisKarlis @Jira @VSTS and replace delivery plans with the feature timeline extension. that is really helpful!