{"record":{"id":"716cfad9713a3a6b","repo":"stride3d/stride","slug":"the-value-of-the-convertback-method-of-this-converter-must","errorCode":null,"errorMessage":"The value of the ConvertBack method of this converter must be a an instance of the Size structure.","messagePattern":"The value of the ConvertBack method of this converter must be a an instance of the Size structure\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToSize.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 Size))\n            {\n                throw new ArgumentException(\"The parameter of this converter must be an instance of the Size structure. Use {sd:Size (arguments)} to construct one.\");\n            }\n\n            var size = (Size)parameter;\n            var result = new Size(size.Width * scalar, size.Height * 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 Size))\n            {\n                throw new ArgumentException(\"The value of the ConvertBack method of this converter must be a an instance of the Size structure.\");\n            }\n            if (!(parameter is Size))\n            {\n                throw new ArgumentException(\"The parameter of the ConvertBack method of this converter must be a an instance of the Size structure.\");\n            }\n            var sizeValue = (Size)value;\n            var sizeParameter = (Size)parameter;\n\n            var scalar = 0.0;\n            if (Math.Abs(sizeParameter.Width) > double.Epsilon)\n            {\n                scalar = sizeValue.Width / sizeParameter.Width;\n            }\n            else if (Math.Abs(sizeParameter.Height) > double.Epsilon)\n            {\n                scalar = sizeValue.Height / sizeParameter.Height;\n            }\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/NumericToSize.cs#L31-L67","documentation":"NumericToSize.ConvertBack reverses the scaling: it takes a Size value and a Size parameter and derives the original scalar. It validates that value is a System.Windows.Size and throws this ArgumentException otherwise. This keeps two-way bindings from receiving unconvertible values from the UI target side.","triggerScenarios":"A two-way MultiBinding/Binding where the target-side value handed to ConvertBack is not a Size — e.g. the target property is a double, string, or Thickness and the converter is used in TwoWay mode.","commonSituations":"Setting Binding Mode=TwoWay on a property that is not of type Size; accidentally wiring NumericToSize in a binding where the control's value is a number; template reuse across differently-typed properties.","solutions":["Use OneWay mode — NumericToSize is designed as a display converter; do not bind TwoWay unless the target is a Size","Ensure the bound target property type is System.Windows.Size","Verify the correct converter (NumericToSize vs NumericToThickness vs plain numeric) is attached","If two-way numeric editing is needed, handle conversion in the view model instead"],"exampleFix":"// before\n<Binding Path=\"Scale\" Converter=\"{sd:NumericToSize}\" ConverterParameter=\"{sd:Size 10,20}\" Mode=\"TwoWay\"/>\n// after\n<Binding Path=\"Scale\" Converter=\"{sd:NumericToSize}\" ConverterParameter=\"{sd:Size 10,20}\" Mode=\"OneWay\"/>","handlingStrategy":"validation","validationCode":"bool CanConvertBack(object value) => value is System.Windows.Size;","typeGuard":"bool IsSize(object v) => v is System.Windows.Size;","tryCatchPattern":"try\n{\n    return converter.ConvertBack(value, typeof(double), sizeParameter, culture);\n}\ncatch (ArgumentException)\n{\n    return Binding.DoNothing;\n}","preventionTips":["Use OneWay mode; NumericToSize is not designed for two-way non-Size targets","Only attach to bindings whose target property is System.Windows.Size","Review binding modes in styles/templates when reusing converters","Return Binding.DoNothing from wrappers on validation failure"],"tags":["wpf","valueconverter","convertback","size"],"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"}