How can I catch the event of the window close button(red X button on window right top corner) in a WPF form? We have got the closing event, window unloaded event also, but w
if it is pressed confirm button in form2 do action, if it is pressed X-button do nothing:
public class Form2
{
public bool confirm { get; set; }
public Form2()
{
confirm = false;
InitializeComponent();
}
private void Confirm_Button_Click(object sender, RoutedEventArgs e)
{
//your code
confirm = true;
this.Close();
}
}
first form:
public void Form2_Closing(object sender, CancelEventArgs e)
{
if(Form2.confirm == false) return;
//your code
}