WPF彈出帶蒙板的消息框
更新時間:2016年12月27日 16:17:45 作者:普通的地球人
這篇文章主要為大家詳細介紹了WPF彈出帶蒙板的消息框,具有一定的參考價值,感興趣的小伙伴們可以參考一下
先看看效果圖
思路
拿到父級窗體的內(nèi)容,放入一個容器里,再在容器里放入一個半透明層.將整個容器賦給父級窗體的內(nèi)容.
關(guān)閉時反向操作.
代碼
消息窗彈出時
/// <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)) }; //父級窗體原來的內(nèi)容 UIElement original = owner.Content as UIElement; owner.Content = null; //容器Grid Grid container = new Grid(); container.Children.Add(original);//放入原來的內(nèi)容 container.Children.Add(layer);//在上面放一層蒙板 //將裝有原來內(nèi)容和蒙板的容器賦給父級窗體 owner.Content = container; //彈出消息框 MessageBox box = new MessageBox() { Owner = owner }; box.tbc_message.Text = message; box.ShowDialog(); }
消息框關(guān)閉時
/// <summary> /// 窗體關(guān)閉事件 /// </summary> private void Window_Closed(object sender, EventArgs e) { //容器Grid Grid grid = this.Owner.Content as Grid; //父級窗體原來的內(nèi)容 UIElement original = VisualTreeHelper.GetChild(grid, 0) as UIElement; //將父級窗體原來的內(nèi)容在容器Grid中移除 grid.Children.Remove(original); //賦給父級窗體 this.Owner.Content = original; }
源碼下載:http://xiazai.jb51.net/201612/yuanma/MessageBox(jb51.net).rar
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
C#中sqlDataRead 的三種方式遍歷讀取各個字段數(shù)值的方法
這篇文章主要介紹了C#中 sqlDataRead 的三種方式遍歷讀取各個字段數(shù)值的方法,每種方法給大家介紹的都非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2018-09-09