How do i resize the monogame window inside an xaml page?

I am trying to constrain a monogame window to 300pxX300px. Here is the reult:


This is like a paint window where it will use the color to draw, but it needs to stay in a 300x300 window.

I guess you are not using MonoGame Window controls to handle the dimensions?

how do you use those?
and also, how do you keep your cursor visible outside of the monogame portion of the window?

public Game1()
{
    graphics = new GraphicsDeviceManager(this);
    Content.RootDirectory = "Content";
    IsMouseVisible = true; // This Bit
}

Not sure how to set the viewport dimensions at this time… took a while and not sure how to set the width yet…

EDIT

Not sure I understood the question really, as the mouse should always be visible… outside…

You were right about IsMouseVisible, thanks :slight_smile:
Too bad about viewport dimensions :frowning:

1 Like

The method to resize depends on how/when you draw in your xaml window.
Do you want to draw a rendertarget of fixed size of 300x300 or the viewport in a xaml control of 300x300 ?

Yes, but I already tried setting the SwapChainPanel width and height to 300

I am actually wondering how to set resolution now :stuck_out_tongue:

Here is my problem so far:

It covers up my other Ui elements.

In windows you would do this i dunno about xmal though.

        public Game1_Usage()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.GraphicsProfile = GraphicsProfile.HiDef;
            Content.RootDirectory = "Content";
            
            this.IsFixedTimeStep = false;
            this.TargetElapsedTime = TimeSpan.FromSeconds(1d / 60);

            this.IsMouseVisible = true;
            this.Window.AllowUserResizing = true;
            this.Window.ClientSizeChanged += TellMeWhenTheUserResizesTheWindow;
        }
        public void TellMeWhenTheUserResizesTheWindow(object sender, EventArgs e)
        {
            /* we are here when the windows being resized */
            //SetUpRenderTargets(); // can do this, depends on how you want it to function
        }

        protected override void Initialize()
        {
            graphics.PreferredBackBufferWidth = 500;
            graphics.PreferredBackBufferHeight = 500;
            graphics.ApplyChanges();
            SetUpRenderTargets();
            base.Initialize();
        }
        public void SetUpRenderTargets()
        {
            PresentationParameters pp = GraphicsDevice.PresentationParameters;
            renderTarget1 = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.PreserveContents);
            renderTarget2 = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, pp.BackBufferFormat, pp.DepthStencilFormat, pp.MultiSampleCount, RenderTargetUsage.PreserveContents);
        }
1 Like

:thumbsup: Thanks! :thumbsup:

For anyone else, put this in Update:

    if (graphics.PreferredBackBufferWidth != <width> || graphics.PreferredBackBufferHeight != <height>)
    {
        graphics.PreferredBackBufferWidth = <width>;
        graphics.PreferredBackBufferHeight = <height>;
        graphics.ApplyChanges();
    }

2 Likes