none
Window Width and Height Changing Automatically on Different Resolutions? RRS feed

  • Question

  • Hello everyone,

    I have tested my application on different computers with different resolutions, and I can't seem to figure out why the main window of my application has Width and Height values different than what I have specified. I have set the Width of the window to 516 and the Height to 687, so I would assume that these values are static. On my current resolution, 1600 x 900, the window size is 516 x 687, which is correct. However, on a resolution of 1366 x 768, the window size is 526 x 697, 10 pixels larger on both dimensions. Here are some screenshots depicting the appearance of my application on the different resolutions:

    Resolution: 1366 x 768

    Application Image

    Resolution: 1600 x 900

    Application - Resolution of 1600 x 900

    Does anyone know why this might be occurring and how I could go about fixing it? I would like a consistent look on all screen sizes and resolutions.

    Thanks in advance for any help!

    Tuesday, September 3, 2013 12:57 AM

All replies

  • Hi Alexander,

      Welcome to MSDN Forum Support.

      All measures in WPF are logical units - not pixels. A logical unit is a 1/96 of an inch. If you increase the resolution of your screen, the user interface stays the same size - it just gets crispier. Since WPF builds on a vector based rendering engine it's incredibly easy to build scaleable user interfaces,so if your application is using WPF,its resolution is independence. But actually, Is WPF Really Resolution Independent? if you refer to Is WPF Really Resolution Independent?, you would find that it would give you the answer to the contrary.This is because that DPI is not in consistent.

      You can use ViewBox to solve this problem. You only store your customer control into Canvas,and put the the Canvas into Viewbox. Then your program is running, it get the resolution firstly, and adjust the size of windows.But its controls are depending on the ViewBox. For more information about ViewBox, you can refer to the articles as follows:

      http://www.vinull.com/Post/2008/03/21/wpf-using-viewbox-and-canvas-to-create-.aspx

     http://wpftutorial.net/ViewBox.html

      http://www.c-sharpcorner.com/uploadfile/yougerthen/working-with-wpf-viewbox-control/


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, September 4, 2013 2:20 AM
    Moderator
  • Hello Jason,

    Thank you for the response! I have thought of using the ViewBox but wasn't sure I should use it. I've used it now, and it works great! There's just a small problem with it: some of my images are not being rendered properly. I'm pretty sure this is because the ViewBox is scaling my images when they're a fixed size. Please take a look at the following screenshot:

    Resolution: 1366 x 768

    Image with ViewBox

    As you can see, the appearance of the window is just as I would like it to be. However, if you look at the Left Arrow image, it is a little distorted. This arrow is an image and not plain Segoe UI Symbol text because I would like the icons to appear on previous versions of Windows. The version of the Segoe UI Symbol font on older versions of Windows is not as updated as it is on Windows 8, and so these icons would not show up on Windows XP, Vista, or 7 unless I made them images.

    Would it be possible to achieve these same results without the image distortion? If so, how?

    Thanks for your help thus far!

    • Edited by Alexander Deeb Wednesday, September 4, 2013 11:50 PM Clarification
    Wednesday, September 4, 2013 11:49 PM