title: Can we know if a window has been closed by the user or code on WPF?
body: <p>I have a window control that I show on my app. Sometimes, the window is closed by the user (clicking on the 'X' button) and sometimes automatically by code. </p>
  
  <p>I'm listening to the Closed event (also tried with Closing) and would like to know in which case I am (user or code). Is this possible?</p>
  
  <p>(I am aware of <a href="https://stackoverflow.com/questions/1175991/how-can-you-determine-whether-a-form-has-been-closed-by-the-user-or-by-your-code">this</a> question but it really doesn't have a satisfactory answer)</p>
  
  <p>EDIT:</p>
  
  <p>I'm looking for a simple solution, or some way of knowing where the event originated. I know I can implement this functionality myself as Sandeep Bansal suggested.</p>