AvaloniaUI/Avalonia · error · NotSupportedException
TemplateBinding does not support OneTime or OneWayToSource b
Error message
TemplateBinding does not support OneTime or OneWayToSource bindings.
What it means
TemplateBinding only forwards values from the templated parent to template children and is inherently OneWay/TwoWay-ish. OneTime (no ongoing propagation) and OneWayToSource (writing back to the templated parent) are semantically incompatible, so CreateInstance throws NotSupportedException.
Source
Thrown at src/Avalonia.Base/Data/TemplateBinding.cs:60
/// <summary>
/// Gets or sets the binding mode.
/// </summary>
public BindingMode Mode { get; set; }
/// <summary>
/// Gets or sets the name of the source property on the templated parent.
/// </summary>
[ConstructorArgument("property")]
[InheritDataTypeFrom(InheritDataTypeFromScopeKind.ControlTemplate)]
public AvaloniaProperty? Property { get; set; }
public BindingBase ProvideValue() => this;
internal override BindingExpressionBase CreateInstance(AvaloniaObject target, AvaloniaProperty? targetProperty, object? anchor)
{
if (Mode is BindingMode.OneTime or BindingMode.OneWayToSource)
throw new NotSupportedException("TemplateBinding does not support OneTime or OneWayToSource bindings.");
return new TemplateBindingExpression(
Property,
Converter,
ConverterCulture,
ConverterParameter,
Mode);
}
}
}
View on GitHub (pinned to 11c5427268)
Solutions
- Use BindingMode.OneWay or TwoWay (or leave Mode unset for the default) with TemplateBinding.
- If you truly need OneTime, use a regular `{Binding RelativeSource={RelativeSource TemplatedParent}}` instead of TemplateBinding.
- If you need OneWayToSource, use a normal binding to the templated parent with explicit mode.
Example fix
// before (XAML):
<ContentPresenter Content="{TemplateBinding Content}" Mode="OneTime"/>
// after:
<ContentPresenter Content="{TemplateBinding Content}"/>
<!-- or for OneTime semantics: -->
<ContentPresenter Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}, Mode=OneTime}"/> Defensive patterns
Strategy: validation
Validate before calling
if (templateBinding.Mode is BindingMode.OneTime or BindingMode.OneWayToSource)
throw new NotSupportedException("TemplateBinding needs OneWay/TwoWay."); Type guard
static bool TemplateModeOk(BindingMode m) => m is BindingMode.OneWay or BindingMode.TwoWay or BindingMode.Default;
Prevention
- Leave TemplateBinding Mode unset (defaults to OneWay).
- Use a normal TemplatedParent binding for OneTime/OneWayToSource.
- Audit XAML for TemplateBinding with explicit Mode.
When it happens
Trigger: Constructing a TemplateBinding with `Mode = BindingMode.OneTime` or `Mode = BindingMode.OneWayToSource`, then applying it so CreateInstance runs.
Common situations: XAML `<TemplateBinding Property="X" Mode="OneTime"/>`. Copying a normal Binding's Mode into a TemplateBinding. Programmatically setting Mode on a TemplateBinding.
Related errors
- Dictionary reset not supported
- BindingExpression has not been started.
- Cannot call AsObservable on a to binding expression which is
- BindingExpression was already attached.
- BindingExpression was already attached to a different proper
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/ef109bbddca12a83.
Report an issue: GitHub.