{"record":{"id":"c138dd4f9421d955","repo":"HandyOrg/HandyControl","slug":"notsupportedexception-bordercircularconverter","errorCode":null,"errorMessage":"NotSupportedException","messagePattern":"NotSupportedException","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/Shared/HandyControl_Shared/Tools/Converter/BorderCircularConverter.cs","lineNumber":28,"sourceCode":"    public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)\n    {\n        if (values.Length != 2 || values[0] is not double width || values[1] is not double height)\n        {\n            return DependencyProperty.UnsetValue;\n        }\n\n        if (width < double.Epsilon || height < double.Epsilon)\n        {\n            return new CornerRadius();\n        }\n\n        var min = Math.Min(width, height);\n        return new CornerRadius(min / 2);\n    }\n\n    public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)\n    {\n        throw new NotSupportedException();\n    }\n}\n","sourceCodeStart":10,"sourceCodeEnd":31,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/HandyControl_Shared/Tools/Converter/BorderCircularConverter.cs#L10-L31","documentation":"BorderCircularConverter computes a CornerRadius (min(width,height)/2) to make an element perfectly round; it is one-way and its ConvertBack always throws NotSupportedException. There is no meaningful inverse from CornerRadius back to the converter's inputs.","triggerScenarios":"Using BorderCircularConverter in a TwoWay/OneWayToSource binding (e.g. binding Border.CornerRadius where the property binding mode is TwoWay), or invoking ConvertBack directly.","commonSituations":"Two-way bindings on editable controls like TextBox where CornerRadius is styled; forgetting Mode=OneWay when adapting sample XAML.","solutions":["Set Mode=OneWay on any binding that uses BorderCircularConverter.","Implement your own two-way converter if reverse conversion is required.","Keep the converter only on display-only properties (CornerRadius of decorative borders)."],"exampleFix":"// before\n<TextBox CornerRadius=\"{Binding Width, Converter={StaticResource BorderCircularConverter}}\" />\n// after\n<TextBox CornerRadius=\"{Binding Width, Mode=OneWay, Converter={StaticResource BorderCircularConverter}}\" />","handlingStrategy":"type-guard","validationCode":"bool usesConverterBack = binding.Mode == BindingMode.TwoWay || binding.Mode == BindingMode.OneWayToSource;\nif (usesConverterBack && converter is BorderCircularConverter) throw new InvalidOperationException(\"Use Mode=OneWay with BorderCircularConverter\");","typeGuard":"static bool IsOneWay(BindingBase b) => b is Binding bd && bd.Mode == BindingMode.OneWay;","tryCatchPattern":"try { var result = converter.ConvertBack(value, targetTypes, parameter, culture); } catch (NotSupportedException) { return Array.Empty<object>(); // one-way converter\n}","preventionTips":["Always use Mode=OneWay with BorderCircularConverter (CornerRadius bindings on editable controls default to TwoWay).","Restrict the converter to decorative, display-only properties.","Review XAML templates that were adapted from other controls for leftover TwoWay modes."],"tags":["converter","wpf","corner-radius","not-supported"],"backgroundTag":"unsupported-operation","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}