{"record":{"id":"4bd49d05fd0caeb3","repo":"dotnet/wpf","slug":"sr-format-sr-readonlypropertynotallowed-property-name","errorCode":null,"errorMessage":"SR.Format(SR.ReadOnlyPropertyNotAllowed, property.Name, GetType().Name)","messagePattern":"SR\\.Format\\(SR\\.ReadOnlyPropertyNotAllowed, property\\.Name, GetType\\(\\)\\.Name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Setter.cs","lineNumber":68,"sourceCode":"            }\n\n            CheckValidProperty(property);\n\n            // No null check for target since null is a valid value.\n\n            _property = property;\n            _value = value;\n            _target = target;\n        }\n\n        private void CheckValidProperty( DependencyProperty property)\n        {\n            ArgumentNullException.ThrowIfNull(property);\n            if (property.ReadOnly)\n            {\n                // Read-only properties will not be consulting Style/Template/Trigger Setter for value.\n                //  Rather than silently do nothing, throw error.\n                throw new ArgumentException(SR.Format(SR.ReadOnlyPropertyNotAllowed, property.Name, GetType().Name));\n            }\n            if( property == FrameworkElement.NameProperty)\n            {\n                throw new InvalidOperationException(SR.Format(SR.CannotHavePropertyInStyle, FrameworkElement.NameProperty.Name));\n            }\n        }\n\n        /// <summary>\n        ///     Seals this setter\n        /// </summary>\n        internal override void Seal()\n        {\n\n            // Do the validation that can't be done until we know all of the property\n            // values.\n\n            DependencyProperty dp = Property;\n            object value = ValueInternal;","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Setter.cs#L50-L86","documentation":"Thrown as ArgumentException from Setter.CheckValidProperty when the DependencyProperty passed to a Setter is read-only (DependencyProperty.ReadOnly == true). Read-only properties are set by the system, never via Style/Template/Trigger setters, so WPF refuses them explicitly.","triggerScenarios":"new Setter(SomeClass.SomeReadOnlyProperty, value) or assigning such a property to Setter.Property — e.g. trying to style read-only properties like ActualWidth, IsMouseOver, or custom readonly DPs registered with RegisterReadOnly.","commonSituations":"Attempting to 'override' a read-only property in a style; confusion between a read-only DP and its read-only counterpart; trying to animate/style values driven by the system.","solutions":["Use a writable DependencyProperty instead (register your own, or style the underlying writable property)","If the property comes from metadata, check property.ReadOnly before assigning Setter.Property","For read-only DPs, manipulate their value via the owner's internal mechanisms, not setters"],"exampleFix":"// before\nnew Setter(UIElement.IsMouseOverProperty, true); // read-only\n// after\n// style a trigger instead\nnew Trigger { Property = UIElement.IsMouseOverProperty, Value = true, Setters = { new Setter(UIElement.OpacityProperty, 0.5) } }","handlingStrategy":"validation","validationCode":"if (property != null && property.ReadOnly) throw new ArgumentException($\"{property.Name} is read-only and cannot be set via a Setter\");","typeGuard":"bool CanStyle(DependencyProperty p) => p != null && !p.ReadOnly;","tryCatchPattern":"try { var s = new Setter(property, value); } catch (ArgumentException) { /* property was read-only */ }","preventionTips":["Check DependencyProperty.ReadOnly before styling a property","Use Triggers to react to read-only properties rather than Setters to set them"],"tags":["wpf","setter","dependency-property","read-only"],"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-21T21:30:21.729Z"}