Primary WPF APIs:
Binding (Mode, UpdateSourceTrigger, RelativeSource, ElementName)INotifyPropertyChangedPrimary Avalonia APIs:
{CompiledBinding ...} and {Binding ...}OneWay, TwoWay, etc.)RelativeSource, ElementName| WPF | Avalonia |
|---|---|
Mode=TwoWay |
same concept |
UpdateSourceTrigger=PropertyChanged |
same intent for editable controls |
RelativeSource AncestorType=... |
same concept |
ElementName=... |
same concept |
Recommended default in migrated views:
WPF XAML:
<TextBox x:Name="QueryBox"
Text="{Binding Query, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Text="{Binding Text, ElementName=QueryBox}" />
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:SearchViewModel">
<StackPanel Spacing="6">
<TextBox x:Name="QueryBox"
Text="{CompiledBinding Query, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Text="{Binding Text, ElementName=QueryBox}" />
</StackPanel>
</UserControl>
using Avalonia.Controls;
using Avalonia.Data;
var query = new TextBox();
query.Bind(TextBox.TextProperty, new Binding("Query")
{
Mode = BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
});
PropertyChanged for the bound property.x:DataType.