The parent form is displayed when the WPF subform is closed, and the wpf form is closed.
This problem has been entangled for two days. Today, with the help of a friend, it is actually very simple. However, as a newbie, it may take a short time to get started with WPF. Therefore, it has plagued me as a problem.
Partial code of the parent form
Private void EditInformation_Click (object sender, RoutedEventArgs e) {this. visibility = Visibility. hidden; // The parent form hides the Page. ALLEdit AE = new Page. ALLEdit (); AE. owner = this; // specifies that the parent form of the child form is its own AE. showDialog (); // subform display}Hide parent form, child form display
Subform code
Protected override void OnClosing (System. ComponentModel. CancelEventArgs e) {this. Owner. Visibility = Visibility. Visible; // display the parent form base. OnClosing (e );}Override the closing event of the child form
The focus is on AE. Owner = this in the parent form;
This statement specifies who the parent form is. Without this statement, when the child form is closed, "object not referenced to instance" will pop up ".
Remember, do not have a new parent form. This is not acceptable.
When a child form pops up in wpf, the parent form cannot be operated.
1. directly use the ShowDialog () function called in the background program to close the subwindow before you can operate on the parent form.
2. To make the form in the middle of the WPF design interface, you can use the WindowStartupLocation = "CenterScreen" attribute in Windows.
Are you satisfied?
How to gray the parent form after the child form pops up in wpf
In fact, Vista has not dimmed the parent window.
However, it is not difficult to achieve this effect.
First, you must use the ShowDialog () method to open a subwindow.
There is also a layer that must overwrite the entire screen (this layer must continue from the Adorner), so that this layer is displayed, and the background color is set to gray (note: this layer must be called before the ShowDialog () method. After the ShowDialog () method is executed, the layer must be closed)