{"record":{"id":"e692f25b3af808aa","repo":"stride3d/stride","slug":"the-number-of-provided-bindings-to-this-converter-must-be-2","errorCode":null,"errorMessage":"The number of provided bindings to this converter must be 2.","messagePattern":"The number of provided bindings to this converter must be 2\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/TrimString.cs","lineNumber":27,"sourceCode":"\nnamespace Stride.Core.Presentation.ValueConverters\n{\n    public class TrimString : OneWayMultiValueConverter<TrimString>\n    {\n        public double MaxWidth { get; set; }\n\n        public TextTrimming TextTrimming { get; set; }\n\n        public TrimmingSource TrimmingSource { get; set; }\n\n        public string WordSeparators { get; set; }\n\n        /// <inheritdoc />\n        public override object Convert([NotNull] object[] values, Type targetType, object parameter, CultureInfo culture)\n        {\n            if (values == null) throw new ArgumentNullException(nameof(values));\n            if (values.Length != 2)\n                throw new ArgumentException(\"The number of provided bindings to this converter must be 2.\");\n\n            var text = values[0]?.ToString() ?? string.Empty;\n            if (values[1] is Control control)\n                return Trimming.ProcessTrimming(control, text, TextTrimming, TrimmingSource, WordSeparators, MaxWidth);\n            if (values[1] is TextBlock textBlock)\n                return Trimming.ProcessTrimming(textBlock, text, TextTrimming, TrimmingSource, WordSeparators, MaxWidth);\n            return text;\n        }\n\n        /// <inheritdoc />\n        public override object ProvideValue(IServiceProvider serviceProvider)\n        {\n            // Note: necessary because properties can be different for each instance of this converter.\n            return this;\n        }\n    }\n}\n","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/presentation/Stride.Core.Presentation.Wpf/ValueConverters/TrimString.cs#L9-L45","documentation":"TrimString is a multi-value converter that requires exactly two bindings: values[0] is the text to trim and values[1] is the Control or TextBlock that displays it. It throws this ArgumentException from Convert (TrimString.cs:27) when the values array length is not 2.","triggerScenarios":"A MultiBinding with fewer or more than 2 child bindings attached to TrimString — e.g. only the text binding without the control binding, or extra bindings for trim options.","commonSituations":"Forgetting the second binding (the target control) when wiring text trimming; adding extra bindings for options that TrimString expects as properties instead; programmatic MultiBinding construction with the wrong count.","solutions":["Ensure the MultiBinding has exactly two bindings: the string and the Control/TextBlock itself.","Bind the second value to the displaying element, e.g. `{Binding RelativeSource={RelativeSource Self}}`.","Move optional settings (TextTrimming, WordSeparators, MaxWidth) onto the converter's properties, not as additional bindings.","Validate values.Length == 2 before calling Convert in code/tests."],"exampleFix":"// before (1 binding only)\n<MultiBinding Converter=\"{StaticResource TrimString}\">\n  <Binding Path=\"Text\"/>\n</MultiBinding>\n// after\n<MultiBinding Converter=\"{StaticResource TrimString}\">\n  <Binding Path=\"Text\"/>\n  <Binding RelativeSource=\"{RelativeSource Self}\"/>\n</MultiBinding>","handlingStrategy":"validation","validationCode":"bool ok = values is { Length: 2 };","typeGuard":"static bool HasValidArity(object[] v) => v is { Length: 2 };","tryCatchPattern":"try { return converter.Convert(values, targetType, param, culture); }\ncatch (ArgumentException) { return string.Empty; }","preventionTips":["Always bind the displaying Control/TextBlock as the second MultiBinding value.","Configure trimming options as converter properties, never as extra bindings.","Review MultiBinding XAML when a converter throws arity errors — the count is almost always off by one binding."],"tags":["wpf","multibinding","valueconverter","arity"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}