private void Window_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
// Whatever code you want if enter key is pressed goes here
}
}
private void DatePicker_PreviewKeyUp(object sender, KeyEventArgs e) {
// event handler to click the default button when you hit enter on DatePicker
if (e.Key == Key.Enter) {
// https://www.codeproject.com/Tips/739358/WPF-Programmatically-click-the-default-button
System.Windows.Input.AccessKeyManager.ProcessKey(null, "\x000D", false);
}
}