Primary WinForms APIs:
PropertyGridSelectedObject / SelectedObjectsPrimary Avalonia patterns:
ItemsControl/TreeView/optional DataGrid-style inspectorsPropertyEntryViewModel rows| WinForms | Avalonia |
|---|---|
automatic PropertyGrid reflection view |
explicit inspector row view-models |
| property tabs/categories | grouped collections + templates |
| built-in editor hosts | explicit editor Control content or template selection |
Avalonia core does not include a direct PropertyGrid control.
WinForms C#:
propertyGrid1.SelectedObject = selectedCustomer;
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:InspectorViewModel">
<ItemsControl ItemsSource="{CompiledBinding Properties}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:PropertyEntryViewModel">
<Grid ColumnDefinitions="180,*" ColumnSpacing="8" Margin="0,2">
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
Text="{CompiledBinding DisplayName}" />
<ContentControl Grid.Column="1"
Content="{CompiledBinding Editor}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</UserControl>
using System.Collections.ObjectModel;
using Avalonia.Controls;
public sealed class PropertyEntryViewModel
{
public string DisplayName { get; init; } = string.Empty;
public Control Editor { get; init; } = new TextBlock();
}
public sealed class InspectorViewModel
{
public ObservableCollection<PropertyEntryViewModel> Properties { get; } = new();
}