I'm launching a WPF Window (using ShowDialog) in the KeyDown handler of a Winforms TextBox. The WPF Window has a button with IsDefault = true. After pressing Enter on the TextBox, the WPF AccessKey mechanism apparently picks it up after window load and triggers the default button.
This issue is not present when launching the window from the KeyDown handler of a WPF TextBox.
Looking for a workaround that would prevent the WPF window from receiving the key press that is being handled in the Winforms textbox.
Here is some sample code that illustrates the problem:
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
var window = new System.Windows.Window();
var button = new System.Windows.Controls.Button
{
IsDefault = true,
Content = "OK",
};
button.Click += (s, args) => window.Close();
window.Content = button;
// window loads then immediately closes due to the default button being triggered
window.ShowDialog();
}
}