我有一个用VSTO开发的C#EXCEL应用程序。我在功能区中有几个按钮,这将打开相应的WPF(xaml)Windows。
我的问题是,当我单击任何功能区按钮时,将打开相应的WPF页面,然后在打开该WPF窗口之前,我无法访问该Excel文件。关闭该WPF窗口后,便可以再次访问excel,因此即使打开任何wpf窗口也要访问excel文件,以便可以同时使用功能区的其他功能。
我该怎么做?
使用Show()
代替ShowDialog()
var window = new MainWindow();
// this will set focus back to excel after window closed.
window.Closed+=(sender, e)=> System.Wndows.Threading.Dispatcher.ExitAllFrames();
window.Show();
System.Windows.Threading.Dispathcer.Run(); // push this to the queue so the textbox can be focused