{"record":{"id":"49916924a22c91d4","repo":"dotnet/wpf","slug":"sr-format-sr-propertynotbindable-dp-name","errorCode":null,"errorMessage":"SR.Format(SR.PropertyNotBindable, dp.Name)","messagePattern":"SR\\.Format\\(SR\\.PropertyNotBindable, dp\\.Name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpression.cs","lineNumber":394,"sourceCode":"            get { return GetReference(_dataItem) == DisconnectedItem; }\n        }\n\n        //------------------------------------------------------\n        //\n        //  Internal Methods\n        //\n        //------------------------------------------------------\n\n        // Create a new BindingExpression from the given Bind description\n        internal static BindingExpression CreateBindingExpression(DependencyObject d,\n                                                DependencyProperty dp,\n                                                Binding binding,\n                                                BindingExpressionBase parent)\n        {\n            FrameworkPropertyMetadata fwMetaData = dp.GetMetadata(d.DependencyObjectType) as FrameworkPropertyMetadata;\n\n            if ((fwMetaData != null && !fwMetaData.IsDataBindingAllowed) || dp.ReadOnly)\n                throw new ArgumentException(SR.Format(SR.PropertyNotBindable, dp.Name), nameof(dp));\n\n            // create the BindingExpression\n            BindingExpression bindExpr = new BindingExpression(binding, parent);\n\n            bindExpr.ResolvePropertyDefaultSettings(binding.Mode, binding.UpdateSourceTrigger, fwMetaData);\n\n            // Two-way Binding with an empty path makes no sense\n            if (bindExpr.IsReflective && binding.XPath == null &&\n                    (binding.Path == null || String.IsNullOrEmpty(binding.Path.Path)))\n                throw new InvalidOperationException(SR.TwoWayBindingNeedsPath);\n\n            return bindExpr;\n        }\n\n\n        // Note: For Nullable types, DefaultValueConverter is created for the inner type of the Nullable.\n        //       Nullable \"Drill-down\" service is not provided for user provided Converters.\n        internal void SetupDefaultValueConverter(Type type)","sourceCodeStart":376,"sourceCodeEnd":412,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/BindingExpression.cs#L376-L412","documentation":"CreateBindingExpression validates that the target DependencyProperty allows data binding: it must be writable and its FrameworkPropertyMetadata must have IsDataBindingAllowed (not read-only and not restrictions like not-data-bindable). Binding a read-only or non-bindable property is rejected with an ArgumentException naming the property.","triggerScenarios":"Calling BindingOperations.SetBinding (or creating a BindingExpression) targeting a read-only dependency property (e.g. UIElement.HasStroke... style read-only DPs), or a property whose metadata sets IsDataBindingAllowed=false (e.g. reads-only triggers properties).","commonSituations":"Attempting to bind to read-only DPs like ActualWidth, ItemsControl.Items, or trigger-only properties; framework migrations exposing properties as read-only; generic helper code that binds any DP without checking dp.ReadOnly.","solutions":["Bind only to writable, data-bindable dependency properties — check dp.ReadOnly and FrameworkPropertyMetadata.IsDataBindingAllowed first","For read-only values, bind the opposite direction (bind another property to the read-only one via OneWay from it), or use the read-only DP's ChangeMachine/Listen via descriptor","Expose your own bindable DP and synchronize it from the read-only source if binding input is required"],"exampleFix":"// before\nlabel.SetBinding(UIElement.ActualWidthProperty, new Binding(\"Width\")); // ArgumentException: PropertyNotBindable\n// after\nlabel.SetBinding(Label.WidthProperty, new Binding(\"Width\"));","handlingStrategy":"validation","validationCode":"var md = dp.GetMetadata(target.GetType()) as FrameworkPropertyMetadata;\nif (dp.ReadOnly || md == null || !md.IsDataBindingAllowed) throw new ArgumentException($\"{dp.Name} is not data-bindable\");","typeGuard":"static bool IsBindable(DependencyProperty dp, DependencyObject d) => !dp.ReadOnly && dp.GetMetadata(d.DependencyObjectType) is FrameworkPropertyMetadata fmd && fmd.IsDataBindingAllowed;","tryCatchPattern":"try { target.SetBinding(dp, binding); } catch (ArgumentException ex) when (ex.Message.Contains(\"bindable\") || ex.ParamName == \"dp\") { /* bind a writable DP instead */ }","preventionTips":["Check dp.ReadOnly and IsDataBindingAllowed before SetBinding","Avoid binding read-only DPs like ActualWidth; bind from them instead","Use compile-time-known writable DPs in helper libraries"],"tags":["wpf","data-binding","read-only-property","argument"],"backgroundTag":"invalid-argument-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}