1
votes

Is there a way to disable, keyboard shortcuts on the RichEditBox control in uwp app? I want to disable the Ctrl-A,Ctrl-2(change line spacing) , Ctrl-R(right alignment) etc. key combinations. RichEditBox is a part of UserControl.

I tried to use KeyDown Event of the richEditBox, but still Ctrl-A select all text:

  private void OnRichEditBoxKeyDown(object sender, KeyRoutedEventArgs e)
    {
        var ctrl = Window.Current.CoreWindow.GetKeyState(Windows.System.VirtualKey.Control);                     

        if (ctrl.HasFlag(CoreVirtualKeyStates.Down))
        {
            if (e.Key == VirtualKey.A)
            {
                e.Handled = true;                    
            }
        }           
    }

How can I disable default ctrl keyboard shortcuts in UWP App? I'm using Microsoft Windows [Version 10.0.14393].

1

1 Answers

3
votes
  1. Override OnKeyDown event in Richeditbox
  2. Check for your key press

Here is a code sample:

In Code Behind

public class MyRichEditBox : RichEditBox
{
    protected override void OnKeyDown(KeyRoutedEventArgs e)
    {
        var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);

        if (ctrl.HasFlag(CoreVirtualKeyStates.Down))
        {
            //return; //if you want to totally disable crtl
            if (e.Key == VirtualKey.A)
            {
                return;
            }
        }
        base.OnKeyDown(e);
    }
}

In XAML

<local:MyRichEditBox/>