AXSG supports valid-XAML inline C# through an explicit CSharp surface in the
default Avalonia XML namespace.
This feature is intended for cases where compact binding or event syntax is no
longer expressive enough and the author needs normal C# expressions or event
statements with access to the local XAML context.
The feature is deliberately explicit:
CSharp.CSharp is the
canonical form for multi-line or context-rich code.CSharp is available directly in the default Avalonia XML namespace. No
additional xmlns prefix is required.
Use this form for short expressions or short event lambdas.
<TextBlock Text="{CSharp Code=source.ProductName}" />
<Button Click="{CSharp Code='(sender, e) => source.ClickCount++'}" />
Notes:
Use this form for multi-line expressions or event statement blocks.
<TextBlock.Text>
<CSharp><![CDATA[
source.ProductName + " #" + source.ClickCount
]]></CSharp>
</TextBlock.Text>
<Button.Click>
<CSharp><![CDATA[
source.ClickCount++;
source.LastAction = "inline code";
]]></CSharp>
</Button.Click>
Inline C# is compiled against explicit context variables.
Value code is compiled as a C# expression and can access:
source: the ambient x:DataType instance when available, otherwise objectroot: the root x:Class instance when available, otherwise objecttarget: the current target object for the assignmentExample:
<TextBlock.Text>
<CSharp><![CDATA[
$"{source.Quantity}x {source.ProductName}"
]]></CSharp>
</TextBlock.Text>
Event code can be either:
Event code can access:
sourceroottargetsenderearg0, arg1, ... for delegate parameters beyond the common two-parameter formExample:
<Button.Click>
<CSharp><![CDATA[
source.ClickCount++;
source.LastAction = $"Clicked by {sender}";
]]></CSharp>
</Button.Click>
source members change.source.root and target are available to the code, but they are treated as
contextual values, not dependency-tracked binding inputs.Supported placements:
Unsupported placements:
The language service treats CSharp content as real C#.
Supported tooling:
For object-element code blocks, the language service resolves the local XAML context first and then analyzes the block against the generated C# context.
Representative diagnostics:
source, root, or target members