{"record":{"id":"ef109bbddca12a83","repo":"AvaloniaUI/Avalonia","slug":"templatebinding-does-not-support-onetime-or-oneway","errorCode":null,"errorMessage":"TemplateBinding does not support OneTime or OneWayToSource bindings.","messagePattern":"TemplateBinding does not support OneTime or OneWayToSource bindings\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/TemplateBinding.cs","lineNumber":60,"sourceCode":"\n        /// <summary>\n        /// Gets or sets the binding mode.\n        /// </summary>\n        public BindingMode Mode { get; set; }\n\n        /// <summary>\n        /// Gets or sets the name of the source property on the templated parent.\n        /// </summary>\n        [ConstructorArgument(\"property\")]\n        [InheritDataTypeFrom(InheritDataTypeFromScopeKind.ControlTemplate)]\n        public AvaloniaProperty? Property { get; set; }\n\n        public BindingBase ProvideValue() => this;\n\n        internal override BindingExpressionBase CreateInstance(AvaloniaObject target, AvaloniaProperty? targetProperty, object? anchor)\n        {\n            if (Mode is BindingMode.OneTime or BindingMode.OneWayToSource)\n                throw new NotSupportedException(\"TemplateBinding does not support OneTime or OneWayToSource bindings.\");\n\n            return new TemplateBindingExpression(\n                Property,\n                Converter,\n                ConverterCulture,\n                ConverterParameter,\n                Mode);\n        }\n    }\n}\n","sourceCodeStart":42,"sourceCodeEnd":71,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/TemplateBinding.cs#L42-L71","documentation":"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.","triggerScenarios":"Constructing a TemplateBinding with `Mode = BindingMode.OneTime` or `Mode = BindingMode.OneWayToSource`, then applying it so CreateInstance runs.","commonSituations":"XAML `<TemplateBinding Property=\"X\" Mode=\"OneTime\"/>`. Copying a normal Binding's Mode into a TemplateBinding. Programmatically setting Mode on a TemplateBinding.","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."],"exampleFix":"// before (XAML):\n<ContentPresenter Content=\"{TemplateBinding Content}\" Mode=\"OneTime\"/>\n\n// after:\n<ContentPresenter Content=\"{TemplateBinding Content}\"/>\n<!-- or for OneTime semantics: -->\n<ContentPresenter Content=\"{Binding Content, RelativeSource={RelativeSource TemplatedParent}, Mode=OneTime}\"/>","handlingStrategy":"validation","validationCode":"if (templateBinding.Mode is BindingMode.OneTime or BindingMode.OneWayToSource)\n    throw new NotSupportedException(\"TemplateBinding needs OneWay/TwoWay.\");","typeGuard":"static bool TemplateModeOk(BindingMode m) => m is BindingMode.OneWay or BindingMode.TwoWay or BindingMode.Default;","tryCatchPattern":null,"preventionTips":["Leave TemplateBinding Mode unset (defaults to OneWay).","Use a normal TemplatedParent binding for OneTime/OneWayToSource.","Audit XAML for TemplateBinding with explicit Mode."],"tags":["bindings","templatebinding","controltemplate","notsupported"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}