[SOLVED] How to get XAML in Monogame for Windows Project

Because store apps have some limitations I have to use a normal Monogame for Windows Project but I need XAML. Right now the only choice with XAML is Monogame for WIndows Store. I tried my best to get xaml to work in the Monogame for Windows project but haven’t succeded.

So my question is:

  • How do I get XAML in the Monogame for Windows Project?

Using VS2013 Ultimate, Win10 Build 10130, Monogame 3.5 (latest dev, can use 3.4)

Are you wanting to target the Windows Store or Windows Desktop? That will be your primary decider.

We currently do not have a template for Windows Desktop that is XAML-based. What you could do is create a WPF project and host your MonoGame view in a WPF control. There have been a few people do this. A web search for “monogame inside wpf” should bring up a few threads to follow.

I tried a lot, but as soon as I get the game1.cs to run it takes over my wpf window. I also tried reverting the Store project to a normal desktop project but no success. If you have any hints how to solve the problem that monogame captures my window I would be really gratefull : )

I definitely need your help here. The last hours I failed trying everything to get monogame + xaml to work. As soon as I run mygame1.Run() I see cornflower blue but my xaml disappears.

But I’m pretty sure some of you people could easily set up a monogame + xaml project, so I need your help how to do this : )

This is going to be the 3. day on this problem. I got DirectX12 to work with xaml to understand how everything interacts. Still as soon as start Monogame it disables all my xaml.

Is there anyone who can setup a monogame desktop project with xaml? Please! I’m right now at the point where I just change random things, hoping for a miracle : (

We have found that it is not a common thing that people want to do. There are few answers because not many people have experience with this. Personally I have never tried and wouldn’t know where to start, except for the web search I listed above.

Ok, thanks for your reply, I really appreciate your support : )

I found a solution, but it’s more like a workaround I haven’t thought of before:
Just create a second window which runs monogame. One for GUI, one for “Game”. In my case this is perfectly fine but for real games this is of course no solution.

Solution is also super simple (detailed explanation if a beginner might stumble upon it):

  1. Create WPF project.

  2. Add Reference to Monogame.Framework (C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows\MonoGame.Framework.dll)

  3. Create a new Monogame for Windows project and copy the Content folder and the Game1.cs class in your project.

  4. Add folowing code in MainWindow.xaml.cs and add a Button in MainWindow.xaml with Click=“StartEngine_Click”

    public partial class MainWindow : Window
    public Game1 monoEngine = new Game1();

         public MainWindow()
         private void StartEngine_Click(object sender, RoutedEventArgs e)

I found the solution: http://mastasoftware.net/2013/10/30/ui-framework-for-monogame-(windows-only)/

Just download his sample code, put it in your project, copy the libs in your project and that’s it :smiley:

It’s based on this: http://blogs.msdn.com/b/nicgrave/archive/2011/03/25/wpf-hosting-for-xna-game-studio-4-0.aspx?Redirected=true

The mastasoftware link is no longer working. Does anyone have a copy of what was there?