AvaloniaInside.MonoGame enables seamless integration of MonoGame content within Avalonia UI applications. Embed MonoGame games and graphics directly into your cross-platform Avalonia controls.
- 🎮 Easy Integration - Add MonoGame content to Avalonia apps with just a control
- 🖼️ Control-Based - Use MonoGame as a standard Avalonia XAML control
- 🎯 Resolution Rendering - Built-in
ResolutionRendererfor resolution-independent rendering - 🔄 Cross-Platform - Works on Desktop platforms (Windows, macOS, Linux)
- ⚡ Simple API - Minimal setup required to get started
Install the package to your project using the command below or visit the NuGet package page for other installation methods.
dotnet add package AvaloniaInside.MonoGameOr via Package Manager Console:
Install-Package AvaloniaInside.MonoGame- .NET 8.0 or .NET 10.0
- Avalonia 11.3.9 or higher
- MonoGame.Framework.DesktopGL 3.8.4.1 or higher
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
public class MyExampleGame : Game
{
private GraphicsDeviceManager _graphics;
private SpriteBatch _spriteBatch;
public MyExampleGame()
{
_graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void LoadContent()
{
_spriteBatch = new SpriteBatch(GraphicsDevice);
}
protected override void Update(GameTime gameTime)
{
// Your game logic here
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
// Your drawing code here
base.Draw(gameTime);
}
}<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:monoGame="clr-namespace:AvaloniaInside.MonoGame;assembly=AvaloniaInside.MonoGame"
x:Class="YourNamespace.YourView">
<monoGame:MonoGameControl Game="{Binding CurrentGame}" />
</UserControl>public class MainViewModel : ViewModelBase
{
public Game CurrentGame { get; set; } = new MyExampleGame();
}Check out the example project in this repository for comprehensive usage examples including:
- Basic MonoGame integration
- Auto-playing Pong game
- Input handling patterns
- Content loading and management
Use the ResolutionRenderer class for resolution-independent rendering:
public class MyGame : Game
{
private ResolutionRenderer _resolutionRenderer;
protected override void Initialize()
{
_resolutionRenderer = new ResolutionRenderer(
this,
new Point(1920, 1080), // Virtual resolution
new Point(1920, 1080) // Actual resolution
);
base.Initialize();
}
protected override void Draw(GameTime gameTime)
{
_resolutionRenderer.BeginDraw();
// Your drawing code here
base.Draw(gameTime);
}
}- Mobile platforms - Not currently supported (iOS, Android)
- Input handling - Device input should be managed through native Avalonia input system rather than MonoGame's input
- Performance - Performance optimizations are ongoing; may not be optimal for all scenarios yet
Contributions are welcome! Please feel free to submit issues, fork the repository, and create pull requests.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ by the AvaloniaInside team
