Note that there are some explanatory texts on larger screens.

plurals
  1. POWhich event can I use to trigger an update to a label before the click event is triggered by hitting enter on the keyboard?
    primarykey
    data
    text
    <p>I have an application that does some pretty complicated calculations when a button is clicked. I'm still trying to get this code more efficient but in the meantime I want to give the user feedback to show that the button has been clicked and the calculations are in progress by updating a label on the UI. </p> <p>The UI is not updated until the click event has been completed so I have to put the code into an event that is called just before the click event's code is triggered.</p> <p>So far I'm using the <code>PreviewMouseLeftButtonDown</code> event which is called before the click event is executed to update the label. This works for a mouse click.<br> BUT if the user hits Enter while the button is in focus it appears as though the <code>PreviewKeyDown</code> AND <code>KeyDown</code> events are never triggered, or at least not triggered before the Click event is triggered.</p> <p>What event can I use to update the label when the enter key is hit OR do you know of another way I can get the label to update before the Click Event's Code is run?</p> <p>Update: I've noticed that the <code>PreviewKeyDown</code> event is triggered before the <code>click</code> event, but I don't see the label updating before the <code>click</code> event code is run. I don't see anything wrong with my code.</p> <pre><code> private void Button1_KeyDown(object sender, KeyEventArgs e) { try { if (e.Key == Key.Return || e.Key == Key.Enter) { lblMessage.Content = "Loading..."; } } catch (Exception) { } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload