开发者

Force DPI for testing in WPF

Is there any way t开发者_开发技巧o 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.)


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜