{"record":{"id":"142dc2c5e761d99e","repo":"stride3d/stride","slug":"the-value-of-the-convertback-method-of-this-converter-must-142dc2","errorCode":null,"errorMessage":"The value of the ConvertBack method of this converter must be a an instance of the Thickness structure.","messagePattern":"The value of the ConvertBack method of this converter must be a an instance of the Thickness structure\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToThickness.cs","lineNumber":49,"sourceCode":"                throw new ArgumentException(\"The value of this converter must be convertible to a double.\", exception);\n            }\n\n            if (!(parameter is Thickness))\n            {\n                throw new ArgumentException(\"The parameter of this converter must be an instance of the Thickness structure. Use {sd:Thickness (arguments)} to construct one.\");\n            }\n\n            var thickness = (Thickness)parameter;\n            var result = new Thickness(thickness.Left * scalar, thickness.Top * scalar, thickness.Right * scalar, thickness.Bottom * scalar);\n            return result;\n        }\n\n        /// <inheritdoc/>\n        public override object ConvertBack(object value, [NotNull] Type targetType, object parameter, CultureInfo culture)\n        {\n            if (!(value is Thickness))\n            {\n                throw new ArgumentException(\"The value of the ConvertBack method of this converter must be a an instance of the Thickness structure.\");\n            }\n            if (!(parameter is Thickness))\n            {\n                throw new ArgumentException(\"The parameter of the ConvertBack method of this converter must be a an instance of the Thickness structure.\");\n            }\n            var thicknessValue = (Thickness)value;\n            var thicknessParameter = (Thickness)parameter;\n\n            var scalar = 0.0;\n            if (Math.Abs(thicknessParameter.Left) > double.Epsilon)\n            {\n                scalar = thicknessValue.Left / thicknessParameter.Left;\n            }\n            else if (Math.Abs(thicknessParameter.Right) > double.Epsilon)\n            {\n                scalar = thicknessValue.Right / thicknessParameter.Right;\n            }\n            else if (Math.Abs(thicknessParameter.Top) > double.Epsilon)","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToThickness.cs#L31-L67","documentation":"NumericToThickness.ConvertBack derives the original scalar by dividing a Thickness value by a Thickness parameter. It validates that value is a System.Windows.Thickness and throws this ArgumentException otherwise, preventing two-way bindings with mismatched target types from reaching the arithmetic.","triggerScenarios":"ConvertBack invoked with value = null, a double, string, or Size because the binding's target property is not a Thickness while the converter is used in TwoWay mode.","commonSituations":"Two-way binding on a non-Thickness property (e.g. a double Slider value) with NumericToThickness attached; copy-pasted bindings from a Thickness-targeted control to a numeric one; programmatic ConvertBack calls in tests with wrong types.","solutions":["Use OneWay binding — this converter is intended for one-way display scaling","Ensure the two-way target property is of type System.Windows.Thickness","Attach the converter only to bindings whose target is a Thickness (e.g. Margin, BorderThickness)","Perform scalar round-trip logic in the view model if two-way numeric editing is required"],"exampleFix":"// before\n<Binding Path=\"Scale\" Converter=\"{sd:NumericToThickness}\" ConverterParameter=\"{sd:Thickness 5}\" Mode=\"TwoWay\"/>\n// after\n<Binding Path=\"Scale\" Converter=\"{sd:NumericToThickness}\" ConverterParameter=\"{sd:Thickness 5}\" Mode=\"OneWay\"/>","handlingStrategy":"validation","validationCode":"bool CanConvertBack(object value) => value is System.Windows.Thickness;","typeGuard":"bool IsThickness(object v) => v is System.Windows.Thickness;","tryCatchPattern":"try\n{\n    return converter.ConvertBack(value, typeof(double), thicknessParameter, culture);\n}\ncatch (ArgumentException)\n{\n    return Binding.DoNothing;\n}","preventionTips":["Use OneWay mode unless the target property is genuinely a Thickness","Attach the converter only to Thickness-typed targets (Margin, BorderThickness, Padding)","Test ConvertBack with real Thickness instances when two-way is required","Handle scalar round-trips in the view model for numeric targets"],"tags":["wpf","valueconverter","convertback","thickness"],"backgroundTag":"type-mismatch","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}