0

I am making an outlook addin, and trying to place a window in the center of outlook. in order to achieve that, I used to do the following:

Outlook.Application olApp;
...
dynamic activeWindow = olApp.ActiveWindow();
wpf_ui_control.Left = activeWindow.Left + (activeWindow.Width / 2) - (wpf_ui_control.Width / 2);
wpf_ui_control.Top = activeWindow.Top + (activeWindow.Height / 2) - (wpf_ui_control.Height / 2);

this of course, proved useless when DPI is not 100%.

I've seen a few examples getting DPI from different controls, but none from an outlook.explorer \ outlook.Inspect (the results of .ActiveWindow() ).

How will I go about getting the DPI, or calculating the center in this case?

Thanks

RanH
  • 740
  • 1
  • 11
  • 31
  • Have you seen this? http://stackoverflow.com/questions/1918877/how-can-i-get-the-dpi-in-wpf – Simon Mourier Nov 08 '15 at 07:37
  • I actually canceled the first answer due to not actually having a visible control yet, but there is another solution there exactly for this occasion. going to check it out! – RanH Nov 08 '15 at 07:42
  • Thanks @SimonMourier this solution did help me! – RanH Nov 08 '15 at 10:50

1 Answers1

0

A good solution was actually suggested here: How can I get the DPI in WPF?

var dpiXProperty = typeof(SystemParameters).GetProperty("DpiX", BindingFlags.NonPublic | BindingFlags.Static);
var dpiYProperty = typeof(SystemParameters).GetProperty("Dpi", BindingFlags.NonPublic | BindingFlags.Static);

var dpiX = (int)dpiXProperty.GetValue(null, null);
var dpiY = (int)dpiYProperty.GetValue(null, null);
Community
  • 1
  • 1
RanH
  • 740
  • 1
  • 11
  • 31