AXSG supports WinUI-style x:Bind for Avalonia through source generation, typed semantic
binding, generated runtime helpers, and language-service support.
Use x:Bind when you want:
TwoWay/BindBack behavior without reflectionThis is an Avalonia-adapted x:Bind model. It follows the WinUI/UWP/Uno concept closely,
but the runtime integration is implemented on top of Avalonia bindings and generated
helpers.
x:Class-backed.x:DataType.DataType=.{x:Bind path,
Mode=OneWay|TwoWay|OneTime,
BindBack=MethodOrSetterCompatibleExpression,
ElementName=SomeControl,
RelativeSource={RelativeSource Self|TemplatedParent|FindAncestor,...},
Source={x:Static ...}|{x:Reference ...}|SomeExpression,
DataType=local:SomeType,
Converter={StaticResource SomeConverter},
ConverterCulture='en-US',
ConverterLanguage='en-US',
ConverterParameter=SomeValue,
StringFormat='Value: {0}',
FallbackValue='...',
TargetNullValue='...',
Delay=250,
Priority=LocalValue,
UpdateSourceTrigger=PropertyChanged|LostFocus|Explicit}
ConverterLanguage is accepted as an alias of ConverterCulture.
<TextBlock Text="{x:Bind Title}" />
<TextBlock Text="{x:Bind FormatTitle(Title)}" />
<TextBlock Text="{x:Bind BuildSummary(FirstName, LastName, Count)}" />
<ItemsControl ItemsSource="{x:Bind Items}">
<ItemsControl.ItemTemplate>
<DataTemplate x:DataType="vm:ItemViewModel">
<TextBlock Text="{x:Bind Name}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
<TextBox x:Name="Editor" />
<TextBlock Text="{x:Bind Text, ElementName=Editor}" />
<TextBlock Tag="{x:Bind Tag, RelativeSource={RelativeSource Self}}" />
<TextBlock Text="{x:Bind Title, RelativeSource={RelativeSource TemplatedParent}, DataType=local:ParentView}" />
<TextBlock Text="{x:Bind DataContext.Title, RelativeSource={RelativeSource FindAncestor, AncestorType=local:ShellView}}" />
Source=<TextBlock Text="{x:Bind Value, Source={x:Static local:BindingSources.Current}, DataType=local:StaticSource}" />
<TextBlock Text="{x:Bind Text, Source={x:Reference Editor}}" />
<TextBlock Text="{x:Bind helpers:UiHelpers.Prefix}" />
<TextBlock Text="{x:Bind Items[SelectedIndex].Name}" />
<ContentPresenter Content="{x:Bind}" />
<Button Click="{x:Bind HandlePrimaryClick}" />
<Button Click="{x:Bind CaptureEditorText(Editor.Text)}" />
<Button Click="{x:Bind Perform(), ElementName=ActionButton}" />
x:Bind source selection is expression-based and compiler-resolved.
Resolution order is:
ElementName, RelativeSource, or SourceSupported source kinds in the current implementation:
RelativeSource Self)RelativeSource TemplatedParent)RelativeSource FindAncestor)Source=...)DataType= can override the semantic source type when the runtime source is known but the
compiler cannot infer a useful CLR type from the source expression alone.
Simple TwoWay:
<TextBox Text="{x:Bind Alias, Mode=TwoWay}" />
Explicit bind-back method:
<TextBox Text="{x:Bind SearchDraft, Mode=TwoWay, BindBack=ApplySearchDraft}" />
Key behavior:
x:Bind expressionAXSG supports Avalonia-oriented Delay and UpdateSourceTrigger options on x:Bind.
Example:
<TextBox Text="{x:Bind SearchDraft,
Mode=TwoWay,
BindBack=ApplySearchDraft,
Delay=250,
UpdateSourceTrigger=Explicit}" />
UpdateSourceTrigger=Explicit stores pending bind-back values until you flush them:
Bindings.Update();
or:
SourceGenMarkupExtensionRuntime.UpdateXBind(this);
For class-backed roots that use x:Bind, AXSG emits:
Bindings.Initialize();
Bindings.Update();
Bindings.StopTracking();
Intended usage:
Initialize() reattaches generated x:Bind trackingUpdate() flushes pending explicit values and refreshes active x:Bind bindingsStopTracking() detaches generated x:Bind subscriptionsSupported conversion and formatting options:
ConverterConverterCultureConverterLanguageConverterParameterStringFormatFallbackValueTargetNullValueThese are part of generated runtime descriptors and are applied before final target assignment/coercion.
Representative x:Bind diagnostics include:
x:Class root for generated x:Bindx:Bind participates in:
The language service understands:
ElementName, RelativeSource, and SourceDataType=x:Bind is compiled into generated evaluators and reflection-free runtime descriptors.
Hot reload uses the generated object-graph path and resets generated x:Bind state when the root graph is repopulated.
Compared with normal Avalonia {Binding} / {CompiledBinding}:
x:Bind is expression-oriented, not just path-orientedx:Bind can call methods and use static members directlyTwoWay reverse flow uses generated bind-back plumbingCompared with inline C#:
x:Bind is the better fit for binding-like expressions and event call expressionsNot currently part of the validated surface:
x:Load integrationx:Bind outside Avalonia binding applicationplan/ folder for engineering work