就两行代码,弄了我一天,上火
[Export(typeof(IWindowManager))] public class AddInWindowManager : WindowManager { protected override System.Windows.Window EnsureWindow(object model, object view, bool isDialog) { var window = base.EnsureWindow(model, view, isDialog); window.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen; if (model is IAddinWindow) { WindowInteropHelper helper = new WindowInteropHelper(window); helper.Owner = new IntPtr(Globals.ThisAddIn.Application.Hwnd); window.Closed += (sender, e) => System.Windows.Threading.Dispatcher.ExitAllFrames(); } return window; } }
var w = IoC.Get(); w.ShowWindow(rootModel, context, settings); System.Windows.Threading.Dispatcher.Run();