Take the 2-minute tour ×

Is there any way to trick a WPF application into thinking that it is running at a certain DPI?

I'd like to test my program at various DPI levels (96, 120, 144, 192) without changing the system setting (which requires a log-out/in under Windows 7).

Can I manually set the size of 1 DIU? (At 96 DPI, 1 DIU = 1 pixel. I'd like to set 1 DIU to 1.25 pixels to imitate 120 DPI.)

share|improve this question
The whole idea of device-independent units is that no matter the screen's resolution, WPF should do the math for you and always render elements at the desired size (i.e. 96 DIU = 1 inch). Are you sure that this testing is really necessary? –  madd0 Mar 6 '11 at 11:57
I have some bitmap graphics in my application, rendered at 4 different sizes for 96, 120, 144 and 192 DPI. I need to test that my image switching code works (I haven't found anything in WPF that does this automatically). I've got a spare box to test with, but it would be nice to do it while debugging in VS somehow. –  Quppa Mar 6 '11 at 12:20
@madd0: Why wouldn't it be necessary? It's called testing for a reason. –  BoltClock Mar 9 '11 at 5:13
"Are you sure that this testing is really necessary?" Neat, never heard that one before –  Glenn Maynard Jun 14 at 21:13
add comment

3 Answers

up vote 3 down vote accepted

You might be able to do what you want if you ScaleTransform the outtermost container. You'd just need to calculate the different between the current dpi and the target dpi and set the scale accordingly.

The other option is to use something like http://research.microsoft.com/en-us/projects/detours/ to override the windows API methods that gives the device dpi. I doubt you would want to go there though.

share|improve this answer
add comment

You can use RenderTargetBitmap to render any Visual with any DPI to any size which may be helpful in your situation.

share|improve this answer
add comment

As Steven above has stated, you can apply a top level ScaleTransform to achieve the same effect, i.e. define it on all your windows. I am doing something similar in my own application. This works best if your app doesn't have many different Window derived classes, since you have to modify every one. E.g. in the root layout item of your Window define something like the following.

<Grid x:Name="LayoutRoot">
      <ScaleTransform ScaleX="1.25" ScaleY="1.25"/>

  <!-- Rest of your app here... -->    

share|improve this answer
add comment

Your Answer


