locked
Windows.Graphics.Display.DisplayInformation - MSDN documentation vs runtime discrepancy

    Question

  • I'm trying to use the Windows.Graphics.Display.DisplayInformation class in a Windows 8.1 app w/ Visual Studio 2013 Update 2 RC.

    The documentation on MSDN notes that the class has several properties, such as:

    • AutoRotationPreferences
    • CurrentOrientation
    • LogicalDpi
    • NativeOrientation
    • RawDpiX, RawDpiY
    • RawPixelsPerViewPixel
    • ResolutionScale
    • StereoEnabled

    However, when I try to use this class, none of these properties exist except for AutoRotationPreferences. This is what I see in the console:

    What gives? I've never seen such a discrepancy before. I need to use the RawPixelsPerViewPixel property, but it simply does not exist...

    Tuesday, April 22, 2014 10:54 AM

Answers

All replies

  • You're looking at the static properties, while these properties are instance properties:





    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, April 22, 2014 12:53 PM
    Moderator
  • Thanks Matt, but I'm referring to the Javascript implementation of this class. DisplayInformation is not a constructor function so this isn't something you 'new up'. Assigning a variable to it makes no difference. The only thing that could possibly make sense would be if the runtime dynamically creates these properties at a later time, or as the result of calling some other function, but I find that unlikely (not to mention, MSDN says nothing special about this class). Device pixel ratio and related info should be available upon application startup, you'd think.

    var di = Windows.Graphics.Display.DisplayInformation;
    console.log(di.rawPixelsPerViewPixel); //undefined
    
    var invalid = new Windows.Graphics.Display.DisplayInformation(); //error, not a constructor function

    I've tested this on Windows Store 8.1 (emulator), Windows Phone 8.1 (emulator and physical device).

    • Edited by brs_kurt Tuesday, April 22, 2014 6:41 PM formatting
    Tuesday, April 22, 2014 6:40 PM
  • The point of showing you this is that you get the actual instance from the OS, even if it's not an object that you "new up".

    And it's exactly the same in the JavaScript implementation.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.



    Tuesday, April 22, 2014 7:52 PM
    Moderator
  • Did you actually run that application and have that line of code execute successfully?  In your examples, you are "newing up" an instance of DisplayInformation - which is fine - that was the first thing I had tried. But for me, it doesn't work for the aforementioned reason:

    If you can create an instance of this and it doesn't blow up at runtime like mine does, then... I don't know, my VS or WinJS libraries are screwed up I guess... Would you mind taking a moment to verify the behavior on your end for me?  

    thank you!

    Tuesday, April 22, 2014 11:28 PM
  • Call Windows.Graphics.Display.DisplayInformation.getForCurrentView() to get an instance of DisplayInformation whose properties you can query.

    As Matt says, you can't call non-static methods off of the class. You need to have an instance.

    --Rob

    • Marked as answer by brs_kurt Wednesday, April 23, 2014 2:33 PM
    Wednesday, April 23, 2014 12:23 AM
    Owner