{"record":{"id":"e88911bda72fe2c5","repo":"MaterialDesignInXAML/MaterialDesignInXamlToolkit","slug":"must-specify-two-values","errorCode":null,"errorMessage":"Must specify two values","messagePattern":"Must specify two values","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/MaterialDesignThemes.Wpf/Converters/CalendarDateCoalesceConverter.cs","lineNumber":20,"sourceCode":"using System.Windows.Data;\n\nnamespace MaterialDesignThemes.Wpf.Converters;\n\n/// <summary>\n/// Help us format the content of a header button in a calendar.\n/// </summary>\n/// <remarks>\n/// Expected items, in the following order:\n///     1) DateTime Calendar.DisplayDate\n///     2) DateTime? Calendar.SelectedDate\n/// </remarks>\npublic class CalendarDateCoalesceConverter : IMultiValueConverter\n{\n    public static readonly CalendarDateCoalesceConverter Instance = new();\n\n    public object? Convert(object?[]? values, Type targetType, object? parameter, CultureInfo culture)\n    {\n        if (values?.Length != 2) throw new ArgumentException(\"Must specify two values\", nameof(values));\n        if (values[0] is not DateTime) throw new ArgumentException($\"First value should be a {nameof(DateTime)}\", nameof(values));\n        if (values[1] is not null && values[1] is not DateTime) throw new ArgumentException($\"Second value should be null or a {nameof(DateTime)}\", nameof(values));\n\n        var selectedDate = (DateTime?)values[1];\n\n        return selectedDate ?? values[0];\n    }\n\n    public object?[]? ConvertBack(object? value, Type[] targetTypes, object? parameter, CultureInfo culture)\n        => null;\n}\n","sourceCodeStart":2,"sourceCodeEnd":32,"githubUrl":"https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit/blob/98edec3a0b96ef272c587b14bcd67ef5f928a7ed/src/MaterialDesignThemes.Wpf/Converters/CalendarDateCoalesceConverter.cs#L2-L32","documentation":"`CalendarDateCoalesceConverter` is an `IMultiValueConverter` that coalesces a calendar's `DisplayDate` with its nullable `SelectedDate`; it expects exactly two values. `Convert` throws `ArgumentException(\"Must specify two values\")` when `values.Length != 2` (including when `values` is null).","triggerScenarios":"Binding the converter from a `MultiBinding` with a number of child bindings other than two, or where one binding is unavailable/`{x:Null}` such that the array length is not 2.","commonSituations":"Editing the XAML and forgetting one of the two bindings; a binding path that fails to resolve so WPF passes a different-length array; reusing the converter for a different multi-value scenario.","solutions":["Provide exactly two child `Binding`s inside the `MultiBinding` using this converter.","Confirm both binding paths resolve at runtime (e.g. the `Calendar` and its `SelectedDate` properties exist).","Do not use this converter for converters that legitimately take a different number of values.","If you need a variant, subclass/replace it rather than passing the wrong arity."],"exampleFix":"<!-- before: only one binding -->\n<MultiBinding Converter=\"{x:Static conv:CalendarDateCoalesceConverter.Instance}\">\n  <Binding Path=\"DisplayDate\"/>\n</MultiBinding>\n\n<!-- after: exactly two -->\n<MultiBinding Converter=\"{x:Static conv:CalendarDateCoalesceConverter.Instance}\">\n  <Binding Path=\"DisplayDate\"/>\n  <Binding Path=\"SelectedDate\"/>\n</MultiBinding>","handlingStrategy":"validation","validationCode":"// Ensure the MultiBinding has exactly two child bindings and both paths resolve.\nif (values is null || values.Length != 2)\n    return DependencyProperty.UnsetValue; // use a safe converter subclass instead","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always supply exactly two child Bindings to this converter.","Verify both binding paths resolve at runtime.","Do not reuse this converter for converters needing a different arity."],"tags":["wpf","converter","multi-binding","calendar","validation","material-design"],"backgroundTag":null,"analyzedSha":"98edec3a0b96ef272c587b14bcd67ef5f928a7ed","analyzedAt":"2026-08-13T14:31:19.111Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}