Primary WinForms APIs:
BindingSourceControl.DataBindingsDataGridView.DataSourcePrimary Avalonia APIs:
{CompiledBinding ...})DataContextINotifyPropertyChanged and collection bindingsListBox, ItemsControl, optional DataGrid package)| WinForms | Avalonia |
|---|---|
BindingSource.DataSource |
DataContext + strongly typed view model |
Control.DataBindings.Add(...) |
XAML binding expressions |
BindingSource.Current |
SelectedItem / explicit current item property |
BindingSource.Filter/Sort |
view-model query/projection state |
BindingSource as implicit UI state holder with explicit view-model properties.ObservableCollection<T> and SelectedItem on the view model.WinForms C#:
var source = new BindingSource();
source.DataSource = customers;
nameTextBox.DataBindings.Add("Text", source, "Name", true, DataSourceUpdateMode.OnPropertyChanged);
customersGrid.DataSource = source;
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:CustomersViewModel">
<Grid RowDefinitions="Auto,*" RowSpacing="8">
<TextBox Grid.Row="0" Text="{CompiledBinding SelectedCustomer.Name}" />
<ListBox Grid.Row="1"
ItemsSource="{CompiledBinding Customers}"
SelectedItem="{CompiledBinding SelectedCustomer}">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="vm:CustomerViewModel">
<TextBlock Text="{CompiledBinding Name}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</UserControl>
using Avalonia.Controls;
var list = new ListBox
{
ItemsSource = viewModel.Customers,
SelectedItem = viewModel.SelectedCustomer
};
var nameBox = new TextBox
{
Text = viewModel.SelectedCustomer?.Name
};
x:DataType with compiled bindings to avoid reflection-heavy binding paths.PropertyChanged.SelectedItem and detail controls to the same selected object.BindingSource state; use explicit filter/sort properties in the view model.