{"record":{"id":"2221fe0643a4c2b2","repo":"lepoco/wpfui","slug":"exceptionenumtobooleanconverterparametermustbeanen","errorCode":null,"errorMessage":"ExceptionEnumToBooleanConverterParameterMustBeAnEnumName","messagePattern":"ExceptionEnumToBooleanConverterParameterMustBeAnEnumName","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"samples/Wpf.Ui.Demo.Mvvm/Helpers/EnumToBooleanConverter.cs","lineNumber":16,"sourceCode":"// This Source Code Form is subject to the terms of the MIT License.\n// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.\n// Copyright (C) Leszek Pomianowski and WPF UI Contributors.\n// All Rights Reserved.\n\nusing System.Windows.Data;\n\nnamespace Wpf.Ui.Demo.Mvvm.Helpers;\n\ninternal class EnumToBooleanConverter : IValueConverter\n{\n    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)\n    {\n        if (parameter is not string enumString)\n        {\n            throw new ArgumentException(\"ExceptionEnumToBooleanConverterParameterMustBeAnEnumName\");\n        }\n\n        if (!Enum.IsDefined(typeof(Wpf.Ui.Appearance.ApplicationTheme), value))\n        {\n            throw new ArgumentException(\"ExceptionEnumToBooleanConverterValueMustBeAnEnum\");\n        }\n\n        var enumValue = Enum.Parse(typeof(Wpf.Ui.Appearance.ApplicationTheme), enumString);\n\n        return enumValue.Equals(value);\n    }\n\n    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)\n    {\n        if (parameter is not string enumString)\n        {\n            throw new ArgumentException(\"ExceptionEnumToBooleanConverterParameterMustBeAnEnumName\");\n        }","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/lepoco/wpfui/blob/ffebacd61058170cf63864b7d5aa730cffff848a/samples/Wpf.Ui.Demo.Mvvm/Helpers/EnumToBooleanConverter.cs#L1-L34","documentation":"Thrown by EnumToBooleanConverter.Convert when the XAML-bound ConverterParameter is not a string. The converter binds a bool (e.g. a RadioButton.IsChecked) to an ApplicationTheme value by name, so it must parse the parameter string against the enum. A non-string parameter (Binding expression, integer, or unset) cannot be matched to an enum name.","triggerScenarios":"A Binding whose ConverterParameter is omitted, set to a resource that resolves to a non-string, or a literal number/object instead of x:Static or a quoted theme name. Convert is invoked by the WPF binding engine each time the bound ApplicationTheme value changes.","commonSituations":"Forgetting ConverterParameter= in XAML, passing ConverterParameter={x:Static ...} to a wrong member type, or a malformed binding like ConverterParameter={Binding Theme} that yields a DependencyObject/unsetValue.","solutions":["In XAML, supply a literal string ConverterParameter that matches an ApplicationTheme name, e.g. ConverterParameter=Dark.","If using x:Static, bind to a string-valued member or wrap with x:Static on a const string field.","Double-check the converter is only attached to ApplicationTheme-bound properties and that the ConverterParameter is a quoted string literal."],"exampleFix":"// before\n<ConverterParameter=\"{Binding CurrentTheme}\" />\n\n// after\n<ConverterParameter=\"Dark\" />\n<!-- or -->\n<RadioButton IsChecked=\"{Binding Theme, Converter={StaticResource EnumToBool}, ConverterParameter=Dark}\" />","handlingStrategy":"validation","validationCode":"if (parameter is not string enumString || string.IsNullOrEmpty(enumString))\n{\n    return Binding.DoNothing; // graceful fallback instead of throwing\n}","typeGuard":"static bool IsValidConverterParameter(object? p) => p is string s && Enum.GetNames(typeof(Wpf.Ui.Appearance.ApplicationTheme)).Contains(s);","tryCatchPattern":null,"preventionTips":["Always set ConverterParameter as a quoted string matching an ApplicationTheme name in XAML.","Use a reusable markup extension or x:Static for theme names to avoid typos.","Return Binding.DoNothing for invalid parameters in custom converters rather than throwing."],"tags":["xaml","binding","converter","enum"],"backgroundTag":null,"analyzedSha":"ffebacd61058170cf63864b7d5aa730cffff848a","analyzedAt":"2026-08-13T21:36:01.370Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}