The parent form is displayed when the WPF subform is closed, and the wpf form is closed.

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.