xaml-csharp-development-skill-for-avalonia

WinForms to Avalonia Modern UI Conversion Index

Table of Contents

  1. Scope and Coverage Contract
  2. WinForms Areas Mapped
  3. Migration Workflow
  4. Granular Reference Set
  5. Full API Coverage Pointers
  6. First Conversion Example
  7. AOT/Trimming and Threading Notes
  8. Troubleshooting

Scope and Coverage Contract

This reference lane maps Windows Forms application patterns to Avalonia 11.3.12 XAML/C# patterns for:

Coverage intent for this lane:

WinForms Areas Mapped

Migration Workflow

  1. Port app shell and window lifetime first.
  2. Replace layout primitives (Dock/Anchor/panels) with Grid-based composition.
  3. Convert event handlers to command + typed binding surfaces.
  4. Port data binding and validation with compiled bindings.
  5. Move dialogs/menus/tray/platform services to Avalonia platform abstractions.
  6. Convert custom rendering/style layers.
  7. Validate behavior parity and performance.
  8. Port high-usage input/date/choice control workflows.
  9. Port advanced interaction patterns (drag/drop, clipboard, notifications).
  10. Replace print/property-grid dependencies with explicit Avalonia patterns.

Granular Reference Set

Full API Coverage Pointers

For exhaustive lookup (not only migration samples):

First Conversion Example

WinForms C#:

var panel = new Panel { Dock = DockStyle.Fill };
var button = new Button { Text = "Save", Anchor = AnchorStyles.Top | AnchorStyles.Right };
button.Click += (_, _) => Save();
panel.Controls.Add(button);
Controls.Add(panel);

Avalonia XAML:

<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:vm="using:MyApp.ViewModels"
             x:DataType="vm:MainViewModel">
  <Grid ColumnDefinitions="*,Auto" RowDefinitions="Auto,*">
    <Button Grid.Column="1"
            Margin="8"
            HorizontalAlignment="Right"
            Command="{CompiledBinding SaveCommand}"
            Content="Save" />
  </Grid>
</UserControl>

Avalonia C#:

using Avalonia;
using Avalonia.Controls;

var grid = new Grid
{
    ColumnDefinitions = ColumnDefinitions.Parse("*,Auto"),
    RowDefinitions = RowDefinitions.Parse("Auto,*")
};

var saveButton = new Button
{
    Content = "Save",
    Margin = new Thickness(8),
    HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Right,
    Command = viewModel.SaveCommand
};
Grid.SetColumn(saveButton, 1);
grid.Children.Add(saveButton);

AOT/Trimming and Threading Notes

Troubleshooting

  1. Converted views feel over-coupled to code-behind.
    • move WinForms event handlers to commands and viewmodel state.
  2. Layout parity is off after replacing Dock and Anchor.
    • use explicit Grid rows/columns and alignment instead of absolute offsets.
  3. Modal flows regress.
    • use Window.ShowDialog(owner) and async command pipelines instead of blocking loops.