title: Possible to cast active Microsoft Word window to WPF Window?
body: <p>I've created a Microsoft Word 2010 vsto add-in which displays a number of custom Wpf Window dialogs when users click on ribbon buttons.</p>
  
  <p>The issue I'm having is that the custom dialog dissapears behind the Word instance if you click the Word icon in the task bar.</p>
  
  <p>After some Googling it appears that this can be fixed by setting the Owner property of my window, but I'm struggling to get the Window instance of the Word application.</p>
  
  <p>I've attached the relevant code below, any suggestions? </p>
  
  <pre><code>using WordNS = Microsoft.Office.Interop.Word;
  
  Window wrapperWindow = new Window();
  wrapperWindow.ResizeMode = ResizeMode.NoResize;
  wrapperWindow.WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
  wrapperWindow.ShowInTaskbar = false;
  wrapperWindow.Content = dialogViewModel.View;
  wrapperWindow.Title = dialogViewModel.Title;
  wrapperWindow.SizeToContent = SizeToContent.WidthAndHeight;
  
  WordNS.Application app = (WordNS.Application)Marshal.GetActiveObject("Word.Application");
  wrapperWindow.Owner = (Window)app.ActiveWindow;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/p9cVD.jpg" alt="Invalid cast exception when casting ActiveWindow to Window"></p>