0

I'm writing an application using C#/WPF and I'm trying to get DPI of a screen. I'm trying to do it this way:

Window MainWindow = Application.Current.MainWindow;
PresentationSource MainWindowPresentationSource = PresentationSource.FromVisual(MainWindow);
Matrix m = MainWindowPresentationSource.CompositionTarget.TransformToDevice;
MessageBox.Show(m.M11.ToString());

But what I get printing m.M11 is always 1. Why is that and how can I get the actual DPI (that is 96, as I suppose)?

krajol
  • 818
  • 3
  • 13
  • 34
  • 1
    I suggest taking a look at http://stackoverflow.com/questions/1918877/how-can-i-get-the-dpi-in-wpf – Daniel Kelley Jan 20 '13 at 11:48
  • @daniel-kelley Ok, thanks. Well, but why should I hard-code there a value of 96? is it because it is some default WPF value? – krajol Jan 20 '13 at 11:53
  • Yes, exactly. See [this question and answers](http://stackoverflow.com/q/4087366/1136211). – Clemens Jan 20 '13 at 12:31

0 Answers0