{"record":{"id":"afa619a3ebcddd9b","repo":"dotnet/wpf","slug":"sr-textrange-propertycannotbeincrementedordecremented","errorCode":null,"errorMessage":"SR.TextRange_PropertyCannotBeIncrementedOrDecremented (formattingProperty.Name)","messagePattern":"SR\\.TextRange_PropertyCannotBeIncrementedOrDecremented \\(formattingProperty\\.Name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRange.cs","lineNumber":817,"sourceCode":"                // We exclude checking thcickness values because we have special treatment for negative values\n                // in TextRangeEdit.SetParagraphProperty - negative values mean: \"leave the value as is\".\n                throw new ArgumentException(SR.Format(SR.TextEditorTypeOfParameterIsNotAppropriateForFormattingProperty, value == null ? \"null\" : value.GetType().Name, formattingProperty.Name), nameof(value));\n            }\n\n            // Check propertyValueAction validity\n            if (propertyValueAction != PropertyValueAction.SetValue &&\n                propertyValueAction != PropertyValueAction.IncreaseByAbsoluteValue &&\n                propertyValueAction != PropertyValueAction.DecreaseByAbsoluteValue &&\n                propertyValueAction != PropertyValueAction.IncreaseByPercentageValue &&\n                propertyValueAction != PropertyValueAction.DecreaseByPercentageValue)\n            {\n                throw new ArgumentException(SR.TextRange_InvalidParameterValue, nameof(propertyValueAction));\n            }\n            // Check if propertyValueAction is applicable to this property\n            if (propertyValueAction != PropertyValueAction.SetValue &&\n                !TextSchema.IsPropertyIncremental(formattingProperty))\n            {\n                throw new ArgumentException(SR.Format(SR.TextRange_PropertyCannotBeIncrementedOrDecremented, formattingProperty.Name), nameof(propertyValueAction));\n            }\n\n            ApplyPropertyToTextVirtual(formattingProperty, value, applyToParagraphs, propertyValueAction);\n        }\n\n        /// <summary>\n        /// Removes all Inline formatting properties from this range.\n        /// Affects only Inline elements: splits the on range borders\n        /// and deletes all Inlines inside the range.\n        /// Properties set on Paragraphs and other enclosing Block elements\n        /// remain intact.\n        /// </summary>\n        public void ClearAllProperties()\n        {\n            Invariant.Assert(this.HasConcreteTextContainer, \"Can't clear properties in non-TextContainer range\");\n\n            ClearAllPropertiesVirtual();\n        }","sourceCodeStart":799,"sourceCodeEnd":835,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Documents/TextRange.cs#L799-L835","documentation":"TextRange.ApplyPropertyValue throws ArgumentException when propertyValueAction is an increment/decrement action (IncreaseByAbsoluteValue, DecreaseByAbsoluteValue, IncreaseByPercentageValue, DecreaseByPercentageValue) but the target property is not incremental per TextSchema.IsPropertyIncremental. Only properties like FontSize that support arithmetic adjustment can use these actions; others (e.g. Foreground) require SetValue. The message includes the offending property name.","triggerScenarios":"Calling ApplyPropertyValue with e.g. PropertyValueAction.IncreaseByAbsoluteValue on a non-incremental property such as Foreground, FontStyle, or FontWeight.","commonSituations":"Building toolbar +/- font-size buttons with generic code paths applied to all formatting properties; loop-based formatting code that reuses the same action for every property.","solutions":["Use PropertyValueAction.SetValue for non-incremental properties","Only use Increase/Decrease actions for incremental properties (e.g. FontSize)","Guard with TextSchema.IsPropertyIncremental(property) before choosing an increment action"],"exampleFix":"// before\nrange.ApplyPropertyValue(ForegroundProperty, Brushes.Red, PropertyValueAction.IncreaseByAbsoluteValue);\n// after\nrange.ApplyPropertyValue(ForegroundProperty, Brushes.Red, PropertyValueAction.SetValue);","handlingStrategy":"validation","validationCode":"if (action != PropertyValueAction.SetValue && !TextSchema.IsPropertyIncremental(property)) action = PropertyValueAction.SetValue;","typeGuard":"bool CanIncrement(DependencyProperty p) => TextSchema.IsPropertyIncremental(p);","tryCatchPattern":"try { range.ApplyPropertyValue(prop, value, action); } catch (ArgumentException ex) { /* property not incremental */ action = PropertyValueAction.SetValue; }","preventionTips":["Only use Increase/Decrease actions for numeric properties like FontSize","Check TextSchema.IsPropertyIncremental before choosing an action"],"tags":["wpf","argument-validation","text-formatting"],"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"}