先看看效果图
思路
拿到父级窗体的内容,放入一个容器里,再在容器里放入一个半透明层.将整个容器赋给父级窗体的内容.
关闭时反向操作.
代码
消息窗弹出时
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
/// <summary>
/// 弹出消息框
/// </summary>
/// <param name="message">消息</param>
/// <param name="owner">父级窗体</param>
public static void showdialog( string message, window owner)
{
//蒙板
grid layer = new grid() { background = new solidcolorbrush(color.fromargb(128, 0, 0, 0)) };
//父级窗体原来的内容
uielement original = owner.content as uielement;
owner.content = null ;
//容器grid
grid container = new grid();
container.children.add(original); //放入原来的内容
container.children.add(layer); //在上面放一层蒙板
//将装有原来内容和蒙板的容器赋给父级窗体
owner.content = container;
//弹出消息框
messagebox box = new messagebox() { owner = owner };
box.tbc_message.text = message;
box.showdialog();
}
|
消息框关闭时
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
/// <summary>
/// 窗体关闭事件
/// </summary>
private void window_closed( object sender, eventargs e)
{
//容器grid
grid grid = this .owner.content as grid;
//父级窗体原来的内容
uielement original = visualtreehelper.getchild(grid, 0) as uielement;
//将父级窗体原来的内容在容器grid中移除
grid.children.remove(original);
//赋给父级窗体
this .owner.content = original;
}
|
源码下载:messagebox.rar
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。