A parent window is designed having keyup event attached. The MainWindow goes like:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Window_KeyUp(object sender, KeyEventArgs e)
{
if (e != null && e.Key == Key.Return)
{
MessageWindow msgWindow = new MessageWindow("KEY UP");
msgWindow.Show();
}
}
}
The MessageWindow having a button OK to close the window, goes like:
public partial class MessageWindow : Window
{
public MessageWindow()
{
InitializeComponent();
}
public MessageWindow(string message) : this()
{
txtMess.Text = message;
}
private void btnOk_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
On receiving the input key as [Return] on parent, a new child window is initialized and is displayed. Press TAB to focus OK button and press Enter. The child MessageWindow pops up again.
Reason: Parent window receives KeyUp event when RETURN key is pressed on child window to close it.
Please provide a way to stop the handling of KeyUp event by parent, other than using a FLAG.