{"record":{"id":"1e0c14ddd46de25c","repo":"unoplatform/uno","slug":"cannot-convert-back-if-both-custom-values-are-the","errorCode":null,"errorMessage":"Cannot convert back if both custom values are the same","messagePattern":"Cannot convert back if both custom values are the same","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml.cs","lineNumber":73,"sourceCode":"\t\t\t{\n\t\t\t\treturn NullOrFalseValue;\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\treturn TrueValue;\n\t\t\t}\n\t\t}\n\n\t\tpublic object ConvertBack(object value, Type targetType, object parameter, string language)\n\t\t{\n\t\t\tif (parameter != null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentException($\"This converter does not use any parameters. You should remove \\\"{parameter}\\\" passed as parameter.\");\n\t\t\t}\n\n\t\t\tif (object.Equals(this.TrueValue, this.NullOrFalseValue))\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException(\"Cannot convert back if both custom values are the same\");\n\t\t\t}\n\n\t\t\treturn this.TrueValue != null ?\n\t\t\t\tvalue.Equals(TrueValue) :\n\t\t\t\t!value.Equals(this.NullOrFalseValue);\n\t\t}\n\t}\n}\n","sourceCodeStart":55,"sourceCodeEnd":82,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SamplesApp/SamplesApp.Samples/Windows_UI_Xaml_Controls/CommandBar/CommandBar_Native_With_AppBarButton_Binding.xaml.cs#L55-L82","documentation":"Thrown by ConvertBack when TrueValue and NullOrFalseValue are equal. Reverse conversion maps the current value back to true/false by comparing against these two; if both are the same object/value, the mapping is ambiguous, so the converter refuses rather than guess.","triggerScenarios":"Configuring the converter resource with TrueValue and NullOrFalseValue set to the same value (e.g. both 'Visible', both same string, both null) and then triggering a TwoWay ConvertBack.","commonSituations":"XAML resource where both properties are left at default (null/null) or explicitly set equal; copy-paste error assigning the same element to both.","solutions":["Give TrueValue and NullOrFalseValue distinct values in the converter resource definition.","If you only need one-way conversion, switch the binding to Mode=OneWay so ConvertBack is never called.","Add an XAML comment / constructor assertion documenting the distinct-values requirement."],"exampleFix":"<!-- before -->\n<conv:FromNullableBoolToCustomValueConverter x:Key=\"C\" TrueValue=\"Visible\" NullOrFalseValue=\"Visible\"/>\n<!-- after -->\n<conv:FromNullableBoolToCustomValueConverter x:Key=\"C\" TrueValue=\"Visible\" NullOrFalseValue=\"Collapsed\"/>","handlingStrategy":"validation","validationCode":"var conv = new FromNullableBoolToCustomValueConverter();\nif (object.Equals(conv.TrueValue, conv.NullOrFalseValue))\n    throw new InvalidOperationException(\"Configure distinct TrueValue and NullOrFalseValue before two-way use.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always assign distinct TrueValue and NullOrFalseValue in the resource.","Avoid TwoWay mode if the two values would be equal.","Add a constructor/runtime check that rejects equal values for two-way usage."],"tags":["xaml","binding","converter","twoway","configuration","samples"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}