WPF Mask pop-up window

Source: Internet
Author: User

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

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.