MessageWindow msgWindow = new MessageWindow("Are you sure you want to delete this file?"); msgWindow.Owner = this; bool result = (bool)msgWindow.ShowDialog(); if(result) { // delete file }
LoginWindow login = new LoginWindow(); bool? dialogResult = login.ShowDialog(); if (dialogResult.HasValue && dialogResult.Value) { // login successful } else { // login canceled }In this example, a login window is created and displayed using the ShowDialog method. If the user logs in successfully, the code executes some code afterwards, but if the user cancels the login, nothing happens. The System.Windows namespace is part of the .NET Framework's Windows Presentation Foundation (WPF) library, which provides a set of APIs for creating desktop applications with rich UI and media.