This project is read-only.

Game Width and Height


How do I change the resolution of my game ?
I have tried setting the width/height from the hosting usercontrol.
    void MainPage_Loaded(object sender, RoutedEventArgs e)
        GameCanvas.Width = 1024;
        GameCanvas.Height = 768;
I have tried changing the Graphics device manager from the Game's constructor
        _graphics = new GraphicsDeviceManager(this);
        _graphics.SynchronizeWithVerticalRetrace = false;
        _graphics.PreferredBackBufferWidth = 1024;
        _graphics.PreferredBackBufferHeight = 768;
I have tried Wiring the ClientSizeChanged event
        Window.ClientSizeChanged += WindowClientSizeChanged;
pivate void WindowClientSizeChanged(object sender, EventArgs e) {
        if (Window.ClientBounds.Width > 0 && Window.ClientBounds.Height > 0) {
            _graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
            _graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;


SimpleNick wrote Apr 27, 2011 at 1:03 AM

I set up an event within the hosting user control like so.
public GameView() {
        LayoutUpdated += GameView_LayoutUpdated;

    void GameView_LayoutUpdated(object sender, EventArgs e) {
        Game.Graphics.PreferredBackBufferWidth = (int)ActualWidth;
        Game.Graphics.PreferredBackBufferHeight = (int)ActualHeight;

I receive a null exception from line 101 within GraphicsDevice.cs

            GetCurrentRenderTarget()._viewport = value;

Debugging resource strings are unavailable. Often the key and arguments provide sufficient information to diagnose the problem. See

What am I doing wrong ?

AName wrote Jun 28, 2011 at 8:35 PM

If you're in full screen, put these in your GameView constructor, immediately after you initialize _graphics:

_graphics.PreferredBackBufferWidth = 1024;
_graphics.PreferredBackBufferHeight = 768;

It works for me in full screen, and I didn't use this line at all:

_graphics.SynchronizeWithVerticalRetrace = false;

Otherwise, my guess is that you want to set the size of the Canvas that is holding your XNA game and/or the actual UserControl's size (make sure it's Width and not x.DesignWidth or w/e).

wrote Jul 5, 2011 at 5:38 PM

wrote Jan 2, 2012 at 4:20 AM

wrote Feb 14, 2013 at 7:13 PM