Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to center a WPF Window in a Excel VSTO addin
    primarykey
    data
    text
    <p>The problem is that a WPF window only takes a system.form.window so I cannot set Excel to be the owner object in my VSTO application, because the VSTO addin only exposes Excel's hwnd, or its active window as a Native Window since it is COM. That means when WindowStartUpLoadation is set to be center owner it doesn't work. So I am forced to work around this.</p> <p>What I have come up with so far after reading <a href="http://blogs.msdn.com/b/wpfsdk/archive/2007/04/03/centering-wpf-windows-with-wpf-and-non-wpf-owner-windows.aspx" rel="noreferrer">this site</a> is to try and manually center the window, but even with his simple example my window never appears centered.</p> <pre><code> private static void CenterWpfWindowInExcel(WpfParameterDialog wpfDialog) { WindowInteropHelper helper = new WindowInteropHelper(wpfDialog); helper.Owner = new IntPtr(Globals.ExcelAddin.Application.Hwnd); // Manually calculate Top/Left to appear centered double nonWpfOwnerLeft = Globals.ExcelAddin.Application.ActiveWindow.Left; // Get non-WPF owner’s Left double nonWpfOwnerWidth = Globals.ExcelAddin.Application.ActiveWindow.Width; // Get non-WPF owner’s Width double nonWpfOwnerTop = Globals.ExcelAddin.Application.ActiveWindow.Top; // Get non-WPF owner’s Top double nonWpfOwnerHeight = Globals.ExcelAddin.Application.ActiveWindow.Height; // Get non-WPF owner’s Height wpfDialog.WindowStartupLocation = WindowStartupLocation.Manual; wpfDialog.Left = nonWpfOwnerLeft + (nonWpfOwnerWidth - wpfDialog.Width)/2; wpfDialog.Top = nonWpfOwnerTop + (nonWpfOwnerHeight - wpfDialog.Height)/2; } </code></pre> <p>Any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload