WPF a message box with the mask

Thinking

To get the content in the parent form, into a container, and then placed in a container a translucent layer. The entire contents of the container assigned to the parent form.

When the message window pops up

///

/// pop-up message box

///

/// news

/// parent form

public static void ShowDialog(string message, Window owner)

{

// mask

Grid layer = new Grid() {
Background = new SolidColorBrush(Color.FromArgb(128, 0, 0, 0)) };

// parent form original content

UIElement original = owner.Content
as UIElement;

owner.Content = null;

// container Grid

Grid container = new Grid();

container.Children.Add (original); // put the original content

container.Children.Add (layer); // put a layer above the mask

// will be equipped with original content and mask containers assigned to the parent form

owner.Content = container;

// pop-up message box

MessageBox box = new MessageBox() {
Owner = owner };

box.tbc_message.Text = message;

box.ShowDialog();

}

The message box is closed

///

/// form closes event

///

private void Window_Closed(object sender,
EventArgs e)

{

// container Grid

Grid
grid = this.Owner.Content as Grid;

// parent form original content

UIElement original =
VisualTreeHelper.GetChild(grid, 0) as UIElement;

// The parent form of the original contents of the container to remove the Grid

grid.Children.Remove(original);

// assign the parent form

this.Owner.Content = orig

Guess you like

Origin blog.csdn.net/weixin_44589117/article/details/93326677
Recommended