There is a button btn_Edit in a window. When that button clicked, a new window opens (new_win) and a click event is added to a button (btn_OK) on new_win. It seems that btn_OK_Click does not work because new_win does not close. Where is the problem?
BC_edit new_win = new BC_edit();
private void btn_Edit_Click(object sender, RoutedEventArgs e)
{
new_win.Title = "a_title";
new_win.ShowDialog();
new_win.btn_OK.Click += new RoutedEventHandler(btn_OK_Click);
}
private void btn_OK_Click(object sender, RoutedEventArgs e)
{
_MyCollection.Add(new MyData
{
Boundary = new_win.Title,
Type = new_win.cmb_BC_edit_type.SelectedItem.ToString(),
Option = new_win.cmb_BC_edit_options.SelectedItem.ToString()
});
new_win.Close();
}
You need to subscribe to the event before you show the new window:
Remember that the
ShowDialogmethod is blocking: it won’t return until the window is closed, so the following statements won’t be executed until then.