none
Get physical screen size

Respuestas

  • @chreno - does that really make sense?  If I have a 10" display at 1366x768 or a 20" display at the same resolution...why doe's the physical monitor size matter to you as the pixel resolution (assuming same DPI) will be same.

    You should review the //BUILD session on layout for multiple form factors which talks about the support we have for these scenarios.


    Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)

    • Marcado como respuesta Bob_BaoMVP sábado, 07 de abril de 2012 13:19
    sábado, 03 de marzo de 2012 18:00
  • Hi Chreno,

    Note that the "correct DPI" is different for different people and does not necessarily map to the physical DPI. Being able to set a custom DPI to magnify applications is an important accessibility affordance for low vision users. If your app tries to override this and apply its own settings based on what is optimal for you then it will be non-optimal and possibly unusable by others.

    --Rob

    • Marcado como respuesta Bob_BaoMVP sábado, 07 de abril de 2012 13:19
    lunes, 05 de marzo de 2012 22:37
    Propietario

Todas las respuestas

  • Metro style apps take the full screen when they start up. So you can put the following code in the Load event of your main window:

    private void UserControl_Loaded(object sender, RoutedEventArgs e)
    {
        var w = this.LayoutRoot.ActualWidth;
        var h = this.LayoutRoot.ActualHeight;
    }

    If you call this code earlier (e.g. in the constructor) the values will be zero.
    • Propuesto como respuesta felipetesc miércoles, 14 de noviembre de 2012 18:52
    jueves, 01 de marzo de 2012 21:06
  • Hi! Thanks for your answer.

    But I would like to get real physical screen size in inch or cm, and not screen resolution or logical size calculated from DIP and the current DPI settings.

    jueves, 01 de marzo de 2012 21:25
  • What do you hope to do with this information?  The Window.Current.Bounds will give you the full screen size of the current window (regardless of any elements layout).

    Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)

    sábado, 03 de marzo de 2012 5:13
  • I have different content sizes for different screen sizes based on a UX research. Eg. if the user has a 10" display, the content width must be 5 cm and on a 20" display the content width must be 7 cm. And I don't care about the resoulution.

    sábado, 03 de marzo de 2012 15:58
  • @chreno - does that really make sense?  If I have a 10" display at 1366x768 or a 20" display at the same resolution...why doe's the physical monitor size matter to you as the pixel resolution (assuming same DPI) will be same.

    You should review the //BUILD session on layout for multiple form factors which talks about the support we have for these scenarios.


    Tim Heuer | Program Manager, XAML | http://timheuer.com/blog | @timheuer

    (if my post has answered your question, please consider using the 'mark as answer' feature in the forums to help others)

    • Marcado como respuesta Bob_BaoMVP sábado, 07 de abril de 2012 13:19
    sábado, 03 de marzo de 2012 18:00
  • I think it does. It is not really a layout problem. We made some experiment on optimal font size, line height, column width for reading. Now we have the concrete numbers for each screen size (it is a bit more complex but the screen size is a quite good approximation). In this scenario the screen resolution doesn't matter, just the physical size. We can't rely on the correct DPI settings, most of the users doesn't use it, I think.

    sábado, 03 de marzo de 2012 22:09
  • Hi Chreno,

    Note that the "correct DPI" is different for different people and does not necessarily map to the physical DPI. Being able to set a custom DPI to magnify applications is an important accessibility affordance for low vision users. If your app tries to override this and apply its own settings based on what is optimal for you then it will be non-optimal and possibly unusable by others.

    --Rob

    • Marcado como respuesta Bob_BaoMVP sábado, 07 de abril de 2012 13:19
    lunes, 05 de marzo de 2012 22:37
    Propietario
  • I'd also add that, as of Windows 7, the DPI gets set to the correct physical DPI value of the display by default. So you're better off assuming that will be correct and sizing your controls appropriately. If the user then wants to adjust the DPI for their personal preferences, your app will just naturally handle it.
    lunes, 05 de marzo de 2012 22:47
  • In my case I want to change the size of the groups SemanticZoom-control.

    Just looking at the resolution will give incorrect info, since I e.g. want two rows of items on a 10" screen @ 1366 and still two rows on the same size screen @ 1920 (at which the system scales the pixels right?)

    What's best practice for finding out what "net" (adjusted) resolution the user is looking at?

    Thank you!

    lunes, 02 de julio de 2012 19:57
  • Just revitalizing an old thread, I Know ... but I really need physical screen size due to rights related concerns for some features of my app. Just to summarize, I need to activate some functions only on device with a Display smaller than 12" and if greater I need to resize the controls rendered into the page.

    I know is Cumbersome, but it is still a requirement and we have no clue on how to obtain this value (if is possible). Tried with LogicalDPI but the value calculated is really far from the real size of the screen (it returns 22" on a laptop :) ).

    Any help is really appreciated.

    Gianluca


    grava

    sábado, 15 de septiembre de 2012 11:40
  • @grava How would that work if somebody is using a projector?

    All you can ever do is take a "best guess" based on the dpi and the number of pixels. There is no guarantee, however, that the dpi settings won't have been customized by the user to something which returns a bogus result.

    sábado, 15 de septiembre de 2012 20:29
  • Hi @all,

    even if this thread seems to be a bit old, here is what i found out about this topic.

    Afaik there is no direct method to get the real physical screen resolution but you can calculate it.

    Therefor you have to combine the Window.Current.Bounds and the DisplayProperties.ResolutionScale so you should get something like this:

    double realWidth = Window.Current.Bounds.Width * (int)DisplayProperties.ResolutionScale / 100

    unfortunately these values are not present on application startup, afaik not even within the OnWindowCreated() method in your App.xaml.cs, so you should wait with the calculation until at least one page was drawn onto the screen i think.

    i hope this will help someone even after this long time :)

    regards christian

    • Propuesto como respuesta ChristianReich viernes, 15 de marzo de 2013 10:16
    viernes, 15 de marzo de 2013 10:16