{"record":{"id":"834c29569677c0a3","repo":"stride3d/stride","slug":"the-parameter-of-the-convertback-method-of-this-converter-834c29","errorCode":null,"errorMessage":"The parameter of the ConvertBack method of this converter must be a an instance of the Thickness structure.","messagePattern":"The parameter 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":53,"sourceCode":"            {\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)\n            {\n                scalar = thicknessValue.Top / thicknessParameter.Top;\n            }\n            else if (Math.Abs(thicknessParameter.Bottom) > double.Epsilon)","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToThickness.cs#L35-L71","documentation":"NumericToThickness.ConvertBack requires both the value and the parameter to be WPF Thickness instances because it multiplies each thickness component by a scalar derived from the parameter. The library throws ArgumentException to fail fast when a caller passes a value or parameter of any other type instead of silently producing a wrong thickness.","triggerScenarios":"Calling NumericToThickness.ConvertBack(value, targetType, parameter, culture) where parameter (or value) is not a System.Windows.Thickness — e.g. passing a double, a string, a custom thickness-like struct, or a binding producing null.","commonSituations":"Wiring the same converter instance in both directions of a TwoWay binding without realizing ConvertBack demands a Thickness parameter; passing ConverterParameter='2.0' instead of a Thickness; copying usage from a similar converter like SumSize that expects Size.","solutions":["Pass a System.Windows.Thickness instance (or a Thickness that the XAML parser creates, e.g. '2') as ConverterParameter in the ConvertBack path.","Ensure the value passed to ConvertBack is also a Thickness; convert scalars on the value side instead.","If the binding is one-way, switch to OneWayValueConverter-style usage so ConvertBack is never invoked."],"exampleFix":"// before\nbinding.ConverterParameter = 2.0; // double -> throws\n// after\nbinding.ConverterParameter = new System.Windows.Thickness(2);","handlingStrategy":"type-guard","validationCode":"bool ok = value is System.Windows.Thickness && parameter is System.Windows.Thickness;","typeGuard":"static bool IsThicknessPair(object value, object parameter) => value is System.Windows.Thickness && parameter is System.Windows.Thickness;","tryCatchPattern":"try { return converter.ConvertBack(value, targetType, parameter, culture); }\ncatch (ArgumentException ex) { /* log ex.ParamName, fall back to original value */ return value; }","preventionTips":["Always pass a Thickness as ConverterParameter for this converter","Use Thickness resources or constructor calls in XAML rather than bare numbers","Keep two-way and one-way converters in separate instances/resources"],"tags":["wpf","valueconverter","type-mismatch","argument"],"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"}