WPF 中非模式对话框的实现

用VC++ 要实现非模式对话框的,可以用下面的代码:

 if(!IsWindow(m_myDlg.m_hWnd))
 {
  m_myDlg.Create(IDD_MY_DLG,this);
 }

但是WPF中的窗口没有句柄,实现非模式对话框就比较麻烦,特别是在主窗口中需要多次显示某个非模式对话框时。

查了一些资料,可以在执行非模式对话框的Closing事件的时候做些手脚:在主窗口类中定义非模式对话框(ShowImage)

        ShowImage showImage = new ShowImage();
        #region 显示/关闭 图像处理的窗口
        delegate void ShowImgWinHide();
        private ShowImgWinHide showImgWillHide;
        private void HideShowImgWin()
        {
            this.showImage.Hide();
        }
        #endregion

 

在主窗口类的构造函数里:

this.showImgWillHide = new ShowImgWinHide(this.HideShowImgWin);

this.showImage.Closing += new CancelEventHandler(ShowImg_Closing);

 

 void ShowImg_Closing(object sender, CancelEventArgs e)
 {
       e.Cancel = true;
       Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal, this.showImgWillHide);
 }

在主窗口类的显示非模式的事件里:

showImage.Show();

这样在主窗口就可以反复调用显示非模式了。

 

 

posted @ 2009-02-19 17:16  乔治国  阅读(889)  评论(0编辑  收藏  举报