简体   繁体   English

当我关闭WPF中的主窗口时Excel关闭

[英]Excel closes when I close the main window in wpf

I have a Excel AddIn project which parses excel workbook and pops a wpf window from excel ribbon when clicked on a button. 我有一个Excel AddIn项目,该项目可解析excel工作簿并在单击按钮时从excel功能区弹出wpf窗口。 the problem is that when I close the window (UI control of type window)pop up. 问题是当我关闭窗口(窗口类型的UI控件)时弹出。 closing action on Window closes the Excel too. 在Windows上执行关闭操作也将关闭Excel。

the code is something like this to show the window. 代码就是这样显示窗口。

MainWindow main= new MainWindow();
main.ShowDialog();

can someone tell what's wrong here? 有人可以告诉我这是怎么回事吗?

I have to question why you are creating a new instance of MainWindow? 我不得不质疑为什么要创建MainWindow的新实例?

What you should be doing is ( http://msdn.microsoft.com/en-us/library/system.windows.window.showdialog.aspx ): 您应该做的是( http://msdn.microsoft.com/zh-cn/library/system.windows.window.showdialog.aspx ):

// Instantiate window
DialogBox dialogBox = new DialogBox();

// Show window modally 
// NOTE: Returns only when window is closed
Nullable<bool> dialogResult = dialogBox.ShowDialog();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM