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