Currently, when I need to convert from DIUs to pixels I use the following:
Window mainWindow = Application.Current.MainWindow; PresentationSource mainWindowPresentationSource = PresentationSource.FromVisual(mainWindow); Matrix m = mainWindowPresentationSource.CompositionTarget.TransformToDevice; Int32 PixelHeight = (Int32)Math.Round(ActualHeight * m.M22); Int32 PixelWidth = (Int32)Math.Round(ActualWidth * m.M11);
However, this requires a visual (MainWindow) to be present on the monitor in question. What about the case where a laptop is connected to an external monitor of different DPI to the laptop screen, and with the MainWindow displayed on the laptop? If no application visuals are displayed on the external monitor how does one determine the DPI factors used by WPF to convert from DIU to pixels on that monitor? Thanks in advance.
-L