protected override void OnKeyDown(KeyRoutedEventArgs e) { if (IsPassword) { // The ctrlDown flag is used to track if the Ctrl key is pressed; if it's actively being used and the most recent // key to trigger OnKeyDown, then treat it as handled. var ctrlDown = InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Control).HasFlag(CoreVirtualKeyStates.Down); // The shift, tab, and directional (Home/End/PgUp/PgDown included) keys can be used to select text and should otherwise // be ignored. if ( e.Key == VirtualKey.Shift || e.Key == VirtualKey.Tab || e.Key == VirtualKey.Left || e.Key == VirtualKey.Right || e.Key == VirtualKey.Up || e.Key == VirtualKey.Down || e.Key == VirtualKey.Home || e.Key == VirtualKey.End || e.Key == VirtualKey.PageUp || e.Key == VirtualKey.PageDown) { base.OnKeyDown(e); return; } // For anything else, continue on (calling base.OnKeyDown) and then if Ctrl is still being pressed, do nothing about it. // The tricky part here is that the SelectionLength value needs to be cached because in an example where the user entered // '123' into the field and selects all of it, the moment that any character key is pressed to replace the entire string, // the SelectionLength is equal to zero, which is not what's desired. Entering a key will thus remove the selected number // of characters from the Text value. OnKeyDown is fortunately called before OnSelectionChanged which enables this. else { // If the C or X keys (copy/cut) are pressed while Ctrl is active, ignore handing them at all. Undo and Redo (Z/Y) should // be ignored as well as this emulates the regular behavior of a PasswordBox. if ((e.Key == VirtualKey.C || e.Key == VirtualKey.X || e.Key == VirtualKey.Z || e.Key == VirtualKey.Y) && ctrlDown) { e.Handled = false; return; } base.OnKeyDown(e); if (_cachedSelectionLength > 0 && !ctrlDown) { Text = Text.Remove(SelectionStart, _cachedSelectionLength); } } } else { base.OnKeyDown(e); } }
private void Thumbnail_OnTapped(object sender, TappedRoutedEventArgs e) { if (InputKeyboardSource.GetKeyStateForCurrentThread(VirtualKey.Shift).HasFlag(CoreVirtualKeyStates.Down)) { // User is doing the range selection return; } e.Handled = true; WeakReferenceMessenger.Default.Send(new MainPageFrameSetConnectedAnimationTargetMessage(sender as UIElement)); var viewModels = sender.GetDataContext <IllustrationViewModel>() .GetMangaIllustrationViewModels() .ToArray(); ConnectedAnimationService.GetForCurrentView().PrepareToAnimate("ForwardConnectedAnimation", (UIElement)sender); App.AppViewModel.RootFrameNavigate(typeof(IllustrationViewerPage), new IllustrationViewerPageViewModel(this, viewModels), new SuppressNavigationTransitionInfo()); }