morevents.blogg.se

Open a closed window
Open a closed window






Private Sub saveButton_Click(sender As Object, e As RoutedEventArgs) The following code demonstrates hiding a window: private void saveButton_Click(object sender, RoutedEventArgs e) =>

open a closed window

If you're going to reuse a window object instance, hide the window instead of closing it. A hidden window can be reopened, unlike a window that has been closed. Instead of closing a window, a window can be hidden with the Hide method. This only works when the window is opened with ShowDialog method. The Button.IsCancel property can be set to true to enable the ESC key to automatically close the window.

open a closed window

Private Sub closeButton_Click(sender As Object, e As RoutedEventArgs) The following code demonstrates closing a modeless window: private void closeButton_Click(object sender, RoutedEventArgs e) => When closing a window that was opened with the Show method, use the Close method. Instead, create a new instance of the window and open it. If you try to show the same window, a InvalidOperationException is thrown. Once a window has been closed, it can't be reopened with the same object instance. If the Close method is used, the DialogResult property is set to false. Private Sub cancelButton_Click(sender As Object, e As RoutedEventArgs) Private Sub okButton_Click(sender As Object, e As RoutedEventArgs) Private void cancelButton_Click(object sender, RoutedEventArgs e) =>

open a closed window

The following code demonstrates setting the DialogResult property: private void okButton_Click(object sender, RoutedEventArgs e) => As soon as the DialogResult property is set to a value, the window closes. When closing a window that was opened with the ShowDialog method, set the DialogResult property to either true or false to indicate an "accepted" or "canceled" state, respectively.

open a closed window

Once a window is closed, the same object instance can't be used to reopen the window.įor more information about the life of a window, see Overview of WPF windows: Window lifetime.








Open a closed window