When you call the ShowDialog() method of the Window instance, it opens it as a model dialog and waits until the user provides an input to it. In this case, the user input is the interaction with the OK and Cancel button. When you click the OK button, the associated event handler assigns true to the DialogResult property and returns to the caller. Similarly, the Cancel button event handler, assigns false to the DialogResult property and returns.
Based on the return value of the ShowDialog() method, which actually returns the value of DialogResult, you can decide whether the user clicked the OK or Cancel button.
The dialog window has been customized by setting the following properties to the Window instance:
- The ShowInTaskbar property has been set to False to prevent the window from being visible in the Taskbar.
- The WindowStyle property has been set to SingleBorderWindow to add a thin border to the window, removing the minimize and maximize buttons from the title bar.
- The Topmost property has been set to True to keep it always visible on top of other windows. This is optional, but good to have.
- The ResizeMode property has been set to NoResize to prevent the user from resizing the dialog window.