WPF popup message box with mask

Source: Internet
Author: User

Ideas

Get the contents of the parent form, put it in a container, and put a translucent layer in the container. Assigns the entire container to the contents of the parent form.

Reverse operation when closed.

Code

When the message window pops up

1 /// <summary>2 ///pop-up message box3 /// </summary>4 /// <param name= "message" >message</param>5 /// <param name= "owner" >parent Form</param>6  Public Static voidShowDialog (stringmessage, Window owner)7 {8     //Masking Board9Grid layer =NewGrid () {Background =NewSolidColorBrush (Color.FromArgb ( -,0,0,0)) };Ten     //parent form's original content OneUIElement original = owner. Content asUIElement; AOwner. Content =NULL; -     //Container Grid -Grid container =NewGrid (); theContainer. Children.add (original);//put the original content -Container. Children.add (layer);//put a layer of masks on top -     //assign the container containing the original content and mask to the parent form -Owner. Content =container; +  -     //pop-up message box +MessageBox box =NewMessageBox () {Owner =owner}; ABox.tbc_message. Text =message; at box. ShowDialog (); -}

When the message box is closed

1 /// <summary>2 ///form Close Event3 /// </summary>4 Private voidWindow_closed (Objectsender, EventArgs e)5 {6     //Container Grid7Grid Grid = This. Owner.content asGrid;8     //parent form's original content9UIElement original = Visualtreehelper.getchild (grid,0) asUIElement;Ten     //Remove the original contents of the parent form in the container grid One grid. Children.remove (original); A     //Assign to parent form -      This. Owner.content =original; -}

SOURCE Download: Messageboxwithlayer.zip

WPF popup message box with mask

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.