The best solution was to use the root element, as suggested earlier, because global labels use functions of the same class that apply to each page, which means that everyone has to process each label separately on each page or risk errors.
My XAML was configured as follows:
<Page Name="root" ...> ... </Page>
My C # to manage this page looks like this:
... namespace DenisQuiz.UWP { public sealed partial class StudyADeck : Page { ... public StudyADeck() { ... // Keyboard shortcuts root.KeyDown += Root_KeyDown; } private void Root_KeyDown(object sender, KeyRoutedEventArgs e) { switch (e.Key) { case Windows.System.VirtualKey.F: FlipCard(); break; case Windows.System.VirtualKey.Right: NextCard(); break; case Windows.System.VirtualKey.Left: PreviousCard(); break; case Windows.System.VirtualKey.S: Frame.GoBack(); // Stop Studying break; case Windows.System.VirtualKey.E: Frame.Navigate(typeof(EditANotecard)); // Edit this card break; case Windows.System.VirtualKey.D: DeleteNotecardAsync(); break; default: break; } } ...
The root name is accessed using any keystroke made when this window was opened, using the expression root.KeyDown += Root_KeyDown . This calls the Root_KeyDown() method, which can then implement any function based on sending the key using the keypress argument KeyRoutedEventArgs e .
My code implements a switch to define key functions.
source share