RichEditBox - KeyDown doesn't capture 'delete' key, but keyup does

150 Views Asked by At

I am using a RichEditBox for a UWP, and have a scenario where I am trying to capture 'delete' key down events. Backspace and other keys work fine, this is specific to delete. For some reason, I have unable to capture 'delete' key down events, but listening to key up works just fine.

Does RichEditBox have some behavior on 'delete' that merits it swallowing the event? Any ideas?

<RichEditBox x:Name="Content"
             AcceptsReturn="False"
             KeyDown="Content_KeyDown"
             KeyUp="Content_KeyUp"
             SelectionChanged="Content_SelectionChanged"
             FontSize="18"
             Style="{StaticResource TitleEditBoxStyle}"/>
private void Content_KeyDown(object sender, KeyRoutedEventArgs e)
{
    // no breakpoint hit, cannot capture delete
    switch (e.Key)
    {
        case Windows.System.VirtualKey.Delete:
        {
            ...
            break;
        }
}
...
private void Content_KeyUp(object sender, KeyRoutedEventArgs e)
{
    // breakpoint hit, key is correct
}
1

There are 1 best solutions below

0
Vincent On BEST ANSWER

Use PreviewKeyDown & PreviewKeyUp instead.