Hi,
Have a problem with dialogresult in a WPF form.
The form is started from main method (static void Main).
Show dialog window start:
new WindowStart().ShowDialog();In window start, this works:
private void button1_Click(object sender, RoutedEventArgs e) { DialogResult = true; }But not this:
void Window_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { DialogResult = true; } }It throws a InvalidOperationException: DialogResult can be set only after Window is created and shown as dialog.
Why does dialogresult work on button click but not on keydown?