Data Binding
Binding Markup Extensions
Binding: the default binding method depending on scope or project setting, can be one of:CompiledBindingReflectionBinding
MultiBindingStaticResource: bind a resource for only once(on initialization)DynamicResource: bind and watch the change of the resourcex:Type: reference for type, not real markup extension but has similar usage.x:Static: reference for static/const members, not real markup extension but has similar usage.
NOTE
Avalonia project created from dotnet template usually enabled <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault> by default. So, you don't need explicit CompiledBinding, you're already using it.
TODO: each binding markup is an extension type, how does it work? https://docs.avaloniaui.net/docs/concepts/markupextensions
Bind from Another Control
xml
<TextBox Name="MyBox" Text="Bind me!">
<TextBlock Text="{Binding #MyBox.Text}" /> 1
2
3
2
3
Relational Binding
$parent: direct parent
xml
<Border Tag="Hello World!">
<TextBlock Text="{Binding $parent.Tag}" />
</Border>1
2
3
2
3
$parent[<idx>]: any level of indirect parent,idxis0based$parent[0]is equivalent to$parent[0]
xml
<Border Tag="Hello World!">
<Border>
<TextBlock Text="{Binding $parent[1].Tag}" />
</Border>
</Border>1
2
3
4
5
2
3
4
5
$parent[<type>]: the first parent of given type
xml
<local:MyControl Tag="Hello World!">
<Decorator>
<TextBlock Text="{Binding $parent[local:MyControl].Tag}" />
</Decorator>
</local:MyControl>1
2
3
4
5
2
3
4
5
NOTE