Thunder.MonoGame.Avalonia
Run a MonoGame game loop inside an Avalonia window — no hacks, no forked MonoGame, no separate process. The library compiles unmodified MonoGame source directly into your project (source-compilation model), and bridges it to Avalonia's OpenGL compositor via a single control: MonoGameControl.
Why this library exists
Avalonia is the leading cross-platform .NET UI framework. MonoGame is the leading cross-platform .NET game framework. Together they make it possible to build apps that are simultaneously rich desktop UIs and real-time 3D/2D games — the kind of tooling, level editors, and game dashboards that normally require two separate processes or a proprietary engine.
The integration is non-trivial: MonoGame's game loop wants to own the render thread; Avalonia's compositor wants the same thread. This library resolves the conflict by running MonoGame's update/draw logic inside Avalonia's OpenGlControlBase.OnOpenGlRender callback, letting the compositor drive the tick rate.
Quick start
<!-- In your Avalonia Window or UserControl -->
<Window xmlns="https://github.com/avaloniaui"
xmlns:mg="clr-namespace:Thunder.MonoGame.Avalonia.Controls;assembly=MonoGame.Framework">
<mg:MonoGameControl x:Name="GameControl" />
</Window>
// In code-behind
GameControl.StartGame(new MyGame());
See 01 — Minimal Setup for the complete walkthrough including required .csproj flags.
How-To Guides
Practical guides for the nine most common integration scenarios:
| Guide | What it covers |
|---|---|
| 01 — Minimal Setup | NuGet install, project flags, XAML namespace, wiring the game control |
| 02 — Input | Keyboard, mouse, and gamepad |
| 03 — Content Pipeline | dotnet-mgcb, loading .xnb assets |
| 04 — Avalonia UI Overlay | Layering Avalonia controls on top of the game surface |
| 05 — SpriteBatch and 2D Rendering | Textures, fonts, GraphicsDevice.Clear |
| 06 — Audio | SoundEffect, SoundEffectInstance, looping music |
| 07 — Advanced Graphics | BasicEffect, RenderTarget2D, instanced draws |
| 08 — Multi-Screen and Sub-Viewports | SubViewGameControl, per-screen rendering |
| 09 — Multi-Window | Multi-monitor patterns, VSync constraint |
API Reference
See the API Reference for all public types and members, with XML documentation and runnable code examples (via Thunder.DocSnippets).