Finally, I found the answer to another question : the method of the OnKeyDowntext control is called before the event KeyDown, so than listening to the event KeyDown, you have to create a subclass RichEditBoxand override the method OnKeyDown. Then in your XAML markup or wherever you instantiate RichEditBox, use your own subclass instead. As a somewhat related example, I created an override TextBoxthat prevents undo and redo operations:
[Windows::Foundation::Metadata::WebHostHidden]
public ref class BetterTextBox sealed : public Windows::UI::Xaml::Controls::TextBox
{
public:
BetterTextBox() {}
virtual ~BetterTextBox() {}
virtual void OnKeyDown(Windows::UI::Xaml::Input::KeyRoutedEventArgs^ e) override
{
Windows::System::VirtualKey key = e->Key;
Windows::UI::Core::CoreVirtualKeyStates ctrlState = Windows::UI::Core::CoreWindow::GetForCurrentThread()->GetKeyState(Windows::System::VirtualKey::Control);
if ((key == Windows::System::VirtualKey::Z || key == Windows::System::VirtualKey::Y) &&
ctrlState != Windows::UI::Core::CoreVirtualKeyStates::None)
{
e->Handled = true;
}
if (!e->Handled)
{
Windows::UI::Xaml::Controls::TextBox::OnKeyDown(e);
}
}
};
source
share