Force DPI for testing in WPF Force DPI for testing in WPF wpf wpf

Force DPI for testing in WPF


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.


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">  <Grid.LayoutTransform>    <TransformGroup>      <ScaleTransform ScaleX="1.25" ScaleY="1.25"/>    </TransformGroup>  </Grid.LayoutTransform>  <!-- Rest of your app here... -->    </Grid>


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