Quantcast
Channel: Windows Presentation Foundation (WPF) forum
Viewing all articles
Browse latest Browse all 18858

Dialogresult work if button click but not on keydown

$
0
0

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?



Viewing all articles
Browse latest Browse all 18858

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>