C# 显示WPF窗口的对话框时发生Win32异常

C# 显示WPF窗口的对话框时发生Win32异常,c#,.net,wpf,visual-studio-2013,C#,.net,Wpf,Visual Studio 2013,我的Excel加载项是用C#,.NET 4.5.1编写的。安装加载项后,Excel中将显示一个功能区选项卡(带功能区按钮)。当我单击一个功能区按钮时,将弹出一个WPF窗口。 它在一段时间内运行良好。但是,在我多次单击功能区按钮并再次单击一个按钮后,什么也没有显示。我检查了日志文件,看到Win32Exception。我不知道是什么原因造成的,以及如何修复。顺便说一句,我的插件在我的电脑上工作得很好,最近我升级到VS2013和.NET4.5.1。过去我使用的是VS2010+.NET4.0。我不确定这

我的Excel加载项是用C#,.NET 4.5.1编写的。安装加载项后,Excel中将显示一个功能区选项卡(带功能区按钮)。当我单击一个功能区按钮时,将弹出一个WPF窗口。 它在一段时间内运行良好。但是,在我多次单击功能区按钮并再次单击一个按钮后,什么也没有显示。我检查了日志文件,看到Win32Exception。我不知道是什么原因造成的,以及如何修复。顺便说一句,我的插件在我的电脑上工作得很好,最近我升级到VS2013和.NET4.5.1。过去我使用的是VS2010+.NET4.0。我不确定这是否与这次升级有关

谢谢

                XLFunctionModel = new MainViewModel(XLApp, UnityContainer);
                xlfuncWindow = new XLFuncWindow();

//http://blogs.microsoft.co.il/blogs/shair/archive/2009/01/16/iwin32window-owner-for-wpf-window.aspx
                var helper = new WindowInteropHelper(xlfuncWindow);
                helper.Owner = wndHandle.Handle;

                xlfuncWindow.DataContext = XLFunctionModel;
                bool? successNullable = xlfuncWindow.ShowDialog();


Name:Win32Exception
Message:Invalid window handle
Target:Void .ctor(Int32, Int32, Int32, Int32, Int32, Int32, Int32, System.String, IntPtr, MS.Win32.HwndWrapperHook[])
Stack:   at MS.Win32.HwndWrapper..ctor(Int32 classStyle, Int32 style, Int32 exStyle, Int32 x, Int32 y, Int32 width, Int32 height, String name, IntPtr parent, HwndWrapperHook[] hooks)
   at System.Windows.Interop.HwndSource.Initialize(HwndSourceParameters parameters)
   at System.Windows.Interop.HwndSource..ctor(HwndSourceParameters parameters)
   at System.Windows.Window.CreateSourceWindow(Boolean duringShow)
   at System.Windows.Window.ShowHelper(Object booleanBox)
   at System.Windows.Window.ShowDialog()

你用过那扇窗户吗?如果你不这样做,你只会把窗户把手漏掉。如果做得够多,Windows就会拒绝创建另一个,kaboom。一定要使用链接到的网页帖子中的代码。我会在其他地方关闭它。我还需要做什么来消除异常?谢谢