AvaloniaUI/Avalonia · error · NotSupportedException

TemplateBinding does not support OneTime or OneWayToSource…

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.

Solutions

  1. Use BindingMode.OneWay or TwoWay (or leave Mode unset for the default) with TemplateBinding.
  2. If you truly need OneTime, use a regular `{Binding RelativeSource={RelativeSource TemplatedParent}}` instead of TemplateBinding.
  3. 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

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


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/ef109bbddca12a83. Report an issue: GitHub.

Appendix: 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)