{"record":{"id":"b88f67a667580eb9","repo":"dotnet/wpf","slug":"sr-markupextensionproperty-templatebindingextension-requires","errorCode":null,"errorMessage":"SR.MarkupExtensionProperty (TemplateBindingExtension requires the Property to be set)","messagePattern":"SR\\.MarkupExtensionProperty \\(TemplateBindingExtension requires the Property to be set\\)","errorType":"exception","errorClass":"System.InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateBindingExtension.cs","lineNumber":57,"sourceCode":"            ArgumentNullException.ThrowIfNull(property);\n\n            _property = property;\n        }\n\n        /// <summary>\n        ///  Return an object that should be set on the targetObject's targetProperty\n        ///  for this markup extension.  For TemplateBindingExtension, this is the object found in\n        ///  a resource dictionary in the current parent chain that is keyed by ResourceKey\n        /// </summary>\n        /// <param name=\"serviceProvider\">ServiceProvider that can be queried for services.</param>\n        /// <returns>\n        ///  The object to set on this property.\n        /// </returns>\n        public override object ProvideValue(IServiceProvider serviceProvider)\n        {\n            if (Property == null)\n            {\n                throw new InvalidOperationException(SR.MarkupExtensionProperty);\n            }\n\n            return new TemplateBindingExpression(this);\n        }\n\n        /// <summary>\n        ///     Property we are binding to\n        /// </summary>\n        [ConstructorArgument(\"property\")]\n        public DependencyProperty Property\n        {\n            get { return _property; }\n            set\n            {\n                ArgumentNullException.ThrowIfNull(value);\n                _property = value;\n            }\n        }","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TemplateBindingExtension.cs#L39-L75","documentation":"TemplateBindingExtension.ProvideValue creates a TemplateBindingExpression from the markup extension, but a template binding is meaningless without a target DependencyProperty. If the Property property is null, ProvideValue throws InvalidOperationException (SR.MarkupExtensionProperty).","triggerScenarios":"Using {TemplateBinding ...} in XAML without specifying the Property, or constructing new TemplateBindingExtension() and calling ProvideValue before assigning Property.","commonSituations":"Hand-written or programmatically generated XAML where the template binding lacks its property argument, e.g. {TemplateBinding} with no value, or a template applied outside a ControlTemplate where binding resolution fails.","solutions":["Set the Property in XAML: use {TemplateBinding Background} instead of {TemplateBinding}.","When creating the extension in code, assign Property (a DependencyProperty) before calling ProvideValue.","Verify the XAML compiles/parses — malformed markup extension usage is the usual root cause."],"exampleFix":"// before\nvar ext = new TemplateBindingExtension();\nvar value = ext.ProvideValue(serviceProvider);\n// after\nvar ext = new TemplateBindingExtension();\next.Property = Control.BackgroundProperty;\nvar value = ext.ProvideValue(serviceProvider);","handlingStrategy":"validation","validationCode":"if (ext == null || ext.Property == null) throw new InvalidOperationException(\"TemplateBindingExtension.Property must be set before ProvideValue\");","typeGuard":"static bool IsUsable(TemplateBindingExtension ext) => ext?.Property != null;","tryCatchPattern":"try { value = ext.ProvideValue(sp); }\ncatch (InvalidOperationException ex) { log(ex.Message); value = DependencyProperty.UnsetValue; }","preventionTips":["Always pass the property name in XAML: {TemplateBinding SomeProperty}","Assign Property before ProvideValue when constructing in code","Validate generated XAML with the XAML compiler before runtime"],"tags":["wpf","xaml","markup-extension","missing-property"],"backgroundTag":"missing-required-argument","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}