Is it possible to disable the "enter" key from triggering the ContentDialog buttons? #1404
-
|
As the question states... I have a dialog with Textboxes that uses enter to trigger an event. Hitting enter within a dialog triggers as if you hit the "primaryButton" and closes the dialog. Is it possible to disable this functionality without disabling using the enter key all together? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Yes, you can. In the WindowsDialog.xaml, whatever you named it, add a PreviewKeyDown event, and the function will look like this. ''' |
Beta Was this translation helpful? Give feedback.
Yes, you can. In the WindowsDialog.xaml, whatever you named it, add a PreviewKeyDown event, and the function will look like this.
'''
private void WindowsDialog_PreviewKeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Enter)
{
// This line prevents the default behavior of the event from occurring.
// It is commonly used to suppress or handle specific input events, such as invalid characters.
e.Handled = true;
}
}
'''