This project has moved. For the latest updates, please go here.

Enter key is being restricted in DateTimePicker

May 1, 2012 at 10:33 PM
Edited May 1, 2012 at 10:53 PM

If I setup a simple DateTimePicker like this:

<xctk:DateTimePicker PreviewKeyDown="DateTimePicker_PreviewKeyDown" />

And then add a handler for the key preview that checks for enter like this:

private void DateTimePicker_PreviewKeyDown(object sender, KeyEventArgs e)
{
    if (e.Key == Key.Enter) MessageBox.Show("Banzai!");
}

Then the PreviewKeyDown (or KeyDown) event never gets fired when the Enter key is pressed. This makes the control quite awkward to use with the DataGrid/DataGridTemplateColumn as this uses Enter to accept a change. Is this a fault or is there any way round this?

Cheers,

EDIT: I've since noticed that the Preview/KeyUp events do fire when the Enter key is hit so it  looks like the control is handling the Preview/KeyDown events.

 As a workaround for this I can create a derived control, override the keypreview event then only pass the enter key to the derived datetimepicker if the calendar is open.