MyraUIGenerator 1.0.10

dotnet add package MyraUIGenerator --version 1.0.10
                    
NuGet\Install-Package MyraUIGenerator -Version 1.0.10
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MyraUIGenerator" Version="1.0.10">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MyraUIGenerator" Version="1.0.10" />
                    
Directory.Packages.props
<PackageReference Include="MyraUIGenerator">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MyraUIGenerator --version 1.0.10
                    
#r "nuget: MyraUIGenerator, 1.0.10"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package MyraUIGenerator@1.0.10
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MyraUIGenerator&version=1.0.10
                    
Install as a Cake Addin
#tool nuget:?package=MyraUIGenerator&version=1.0.10
                    
Install as a Cake Tool

Myra UI Generator

NuGet License .NET

Myra UI Generator icon

A source generator for Myra UI XML files that automatically creates strongly-typed C# accessor classes.

Features

  • 🔧 Automatic Code Generation: Scans Myra XML files and generates strongly-typed C# classes
  • 🎯 Type Safety: Compile-time access to UI widgets with IntelliSense support
  • ⚙️ Configurable: Customize namespace and XML directory paths
  • 🚀 Zero Runtime Overhead: Pure compile-time code generation
  • 📦 NuGet Package: Easy to add to any MonoGame + Myra project

Installation

dotnet add package MyraUIGenerator

Or add to your .csproj:

<ItemGroup>
  <PackageReference Include="MyraUIGenerator" Version="1.0.0" />
</ItemGroup>

Usage

1. Add XML Files to AdditionalFiles

In your .csproj, include your Myra XML files:

<ItemGroup>
  <AdditionalFiles Include="Content/UI/*.xml" />
</ItemGroup>

2. Configure (Optional)

Create or update .editorconfig in your project root:

[*.cs]
# Namespace for generated UI classes
myra_ui_generator.namespace = YourNamespace.UI.Generated

# Directory where XML files are located (relative to project root)
myra_ui_generator.xml_directory = Content/UI

If not configured, defaults are:

  • Namespace: GeneratedUI
  • Directory: Content/UI

3. Use Generated Classes

For a file named TitleScreen.xml:

using YourNamespace.UI.Generated;
using Myra.Graphics2D.UI;

// Load the UI
var project = UiLoader.Load("TitleScreen.xml");

// Create and initialize the generated class
var ui = new TitleScreenUI();
ui.Initialize(project.Root);

// Use strongly-typed access
ui.StartButton.Click += OnStartClicked;
ui.TitleLabel.Text = "Welcome!";
ui.SettingsButton.IsEnabled = true;

Generated Code

For TitleScreen.xml with widgets:

  • Id="StartButton" (Button)
  • Id="TitleLabel" (Label)
  • Id="SettingsButton" (Button)

The generator creates TitleScreenUI.g.cs:

namespace YourNamespace.UI.Generated;

public partial class TitleScreenUI
{
    public Button StartButton { get; private set; }
    public Label TitleLabel { get; private set; }
    public Button SettingsButton { get; private set; }

    public void Initialize(Widget root)
    {
        StartButton = root.FindChildById("StartButton") as Button;
        TitleLabel = root.FindChildById("TitleLabel") as Label;
        SettingsButton = root.FindChildById("SettingsButton") as Button;
    }
}

Supported Widget Types

The generator recognizes these Myra XML elements:

  • Label → Label
  • Button → Button
  • CheckBox → CheckBox
  • TextBox → TextBox
  • Panel → Panel
  • VerticalStackPanel → VerticalStackPanel
  • HorizontalStackPanel → HorizontalStackPanel
  • Grid → Grid
  • ScrollViewer → ScrollViewer
  • Slider → Slider
  • ProgressBar → ProgressBar
  • ListBox → ListBox
  • ComboBox → ComboBox
  • Image → Image
  • TextBlock → TextBlock
  • Unknown types → Widget (fallback)

Property Names

Property names in the generated classes match the Id attribute values from your XML files exactly. For example:

  • Widget with Id="StartButton" → Property named StartButton
  • Widget with Id="TitleLabel" → Property named TitleLabel
  • Widget with Id="HealthBar" → Property named HealthBar

Requirements

  • .NET Standard 2.0 or later
  • Myra UI library
  • MonoGame (or compatible framework)

Documentation

📚 Complete documentation is available in the GitHub Wiki

The wiki includes:

  • Getting started guides
  • Configuration options
  • Usage examples and patterns
  • API reference
  • Troubleshooting guide
  • Contributing guidelines

Wiki documentation is automatically synced from the wiki/ directory in this repository.

License

MIT License - see LICENSE file for details.

Contributing

Contributions welcome! Please open an issue or pull request on GitHub.

Changelog

1.0.0

  • Initial release
  • Configurable namespace and directory
  • Support for common Myra widget types
  • Property names match XML Id attributes exactly
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.10 447 12/16/2025
1.0.9 457 12/10/2025
1.0.8 459 12/10/2025
1.0.7 316 12/7/2025
1.0.2 527 12/7/2025
1.0.1 530 12/7/2025
1.0.0 233 12/7/2025