Due to the interface design needs, to add mask effect to the pop-up window, Baidu and Google search for half a day, unexpectedly there is no satisfactory solution, finally can only find a way to achieve a, the principle or relatively simple, now share to everyone.
First look at the effect:
The principle is very simple, when starting the project, first in the main form at the root of the grid to add a control, set the color and transparency, hide:
<Grid>
<button content= "test pop-up window" width= "height=" click= "Button_Click"/>
<stackpanel x:name= "spmasking" opacity= "0.4" background= "Black" visibility= "collapsed"/>
</Grid>
Here I use the stack panel, specifically nothing has affected. Black background 0.4 Transparency just renders the mask effect.
When you need a mask to pop the window, call the method
public static void ShowDialog (Window owner, window window)
{
StackPanel spmasking = controlhelper.getchildobject<stackpanel> (owner, "spmasking");
spmasking.visibility = visibility.visible;
Window. ShowDialog ();
}
When you need to close the mask effect, call the method
public virtual void Clearmask (object sender, EventArgs e)
{
var owner = Application.Current.MainWindow;
StackPanel spmasking = controlhelper.getchildobject<stackpanel> (owner, "spmasking");
spmasking.visibility = visibility.collapsed;
}
This allows you to implement a mask pop-up window
Some students may want to ask, in this case, the title of the top row of the form, zoom Out button, and not blocked. Here, my approach is to hide the default style, the application Grid encapsulates the new custom style, and then apply Grid.columnspan Grid.rowspan cross-column masking mask, if there are problems with the partner welcome message.
Example code link: Https://pan.baidu.com/s/1eS2B5ZW Password: 2KMF
WPF Mask pop-up window