GraphicsDevice.Viewport doesn't return the real size of UWP game window

I am trying to make the UWP version of my game fit the game window every time I resize the window. But no matter what size the game window is set to, GraphicsDevice.Viewport.Width and GraphicsDevice.Viewport.Height always return the same values (which are 800 and 480). I’m not even sure if GraphicsDevice.Viewport is the right place to turn to. Can someone help me on this issue? Thanks very much!

Try these:

Graphics.GraphicsDevice.DisplayMode.Width
Graphics.GraphicsDevice.DisplayMode.Height

Game.Window.ClientBounds will always return the size of the window.

Thanks very much @Tom ! That worked! :smiley:
One more small question: Do you know how to get the resolution of the monitor on which the game is displayed?

Thanks @KuzDeveloper! I tried that but it didn’t seem to work. Tom’s answer is the right solution :slightly_smiling:

For getting the resolution of the monitor try using this:
GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height

I’d like to qualify @Tom 's answer:

Game.Window.ClientBounds will be correct, but only after the game’s Initialize has been called. Looking at Game.Window.ClientBounds in the Game's constructor or Initialize methods will not return proper values.

Observe the following simplified Game1.cs file:

    public class Game1 : Game
    {
        GraphicsDeviceManager graphics;

        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Debug.WriteLine("Constructor:" + GetResolution());
        }

        string GetResolution()
        {
            return $"{Window.ClientBounds.Width}, {Window.ClientBounds.Height}";
        }

        protected override void Initialize()
        {
            Debug.WriteLine("Start of Initialize:" + GetResolution());
            base.Initialize();
            Debug.WriteLine("End of Initialize:" + GetResolution());
        }

        int frameCount = 0;
        protected override void Update(GameTime gameTime)
        {
            if(frameCount % 100 == 0)
            {
                Debug.WriteLine($"Update with frame {frameCount}:" + GetResolution());
            }

            frameCount++;
            base.Update(gameTime);
        }
    }

This outputs the following:

Constructor:3840, 2160
Start of Initialize:3840, 2160
End of Initialize:3840, 2160
Update with frame 0:1200, 900
Update with frame 100:1200, 900
Update with frame 200:1200, 900
Update with frame 300:1200, 900
...

My primary monitor is a 4k monitor, so the resolution values returned at the beginning of execution is the full resolution of my primary display. Once Game starts, the actual game resolution is returned.

For future readers, I just wanted to add that the same behavior exists on Desktop GL projects on Windows.