The message box with masks is displayed in WPF, And the masks are displayed in wpf.

Source: Internet
Author: User

The message box with masks is displayed in WPF, And the masks are displayed in wpf.

 

Ideas

Get the content of the parent form, put it in a container, and then put a translucent layer in the container. Assign the entire container to the content of the parent form.

Reverse operation when disabled.

 

Code

When the message window pops up

1 /// <summary> 2 /// pop-up message box 3 /// </summary> 4 /// <param name = "message"> message </param> 5 /// <param name = "owner"> parent form </param> 6 public static void ShowDialog (string message, window owner) 7 {8 // mask 9 Grid layer = new Grid () {Background = new SolidColorBrush (Color. fromArgb (128, 0, 0, 0)}; 10 // the original content of the parent Form 11 UIElement original = owner. content as UIElement; 12 owner. content = null; 13 // container Grid14 Grid container = new Grid (); 15 container. children. add (original); // put the original content 16 iner. children. add (layer); // place a layer of mask on top 17 // assign the container containing the original content and mask to the parent Form 18 owner. content = container; 19 20 // pop-up message box 21 MessageBox box = new MessageBox () {Owner = owner}; 22 box. tbc_message.Text = message; 23 box. showDialog (); 24}

When the message box is closed

1 /// <summary> 2 // form close event 3 /// </summary> 4 private void Window_Closed (object sender, EventArgs e) 5 {6 // container Grid 7 Grid grid = this. owner. content as Grid; 8 // original Content of the parent form 9 UIElement original = VisualTreeHelper. getChild (grid, 0) as UIElement; 10 // remove the original content of the parent form from the container Grid. children. remove (original); 12 // assigned to the parent Form 13 this. owner. content = original; 14}

Source code download: MessageBoxWithLayer.zip

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.