lepoco/wpfui · error · ArgumentException

ExceptionEnumToBooleanConverterParameterMustBeAnEnumName

Error message

ExceptionEnumToBooleanConverterParameterMustBeAnEnumName

What it means

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.

Source

Thrown at samples/Wpf.Ui.Demo.Mvvm/Helpers/EnumToBooleanConverter.cs:16

// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
// Copyright (C) Leszek Pomianowski and WPF UI Contributors.
// All Rights Reserved.

using System.Windows.Data;

namespace Wpf.Ui.Demo.Mvvm.Helpers;

internal class EnumToBooleanConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (parameter is not string enumString)
        {
            throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName");
        }

        if (!Enum.IsDefined(typeof(Wpf.Ui.Appearance.ApplicationTheme), value))
        {
            throw new ArgumentException("ExceptionEnumToBooleanConverterValueMustBeAnEnum");
        }

        var enumValue = Enum.Parse(typeof(Wpf.Ui.Appearance.ApplicationTheme), enumString);

        return enumValue.Equals(value);
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        if (parameter is not string enumString)
        {
            throw new ArgumentException("ExceptionEnumToBooleanConverterParameterMustBeAnEnumName");
        }

View on GitHub (pinned to ffebacd610)

Solutions

  1. In XAML, supply a literal string ConverterParameter that matches an ApplicationTheme name, e.g. ConverterParameter=Dark.
  2. If using x:Static, bind to a string-valued member or wrap with x:Static on a const string field.
  3. Double-check the converter is only attached to ApplicationTheme-bound properties and that the ConverterParameter is a quoted string literal.

Example fix

// before
<ConverterParameter="{Binding CurrentTheme}" />

// after
<ConverterParameter="Dark" />
<!-- or -->
<RadioButton IsChecked="{Binding Theme, Converter={StaticResource EnumToBool}, ConverterParameter=Dark}" />
Defensive patterns

Strategy: validation

Validate before calling

if (parameter is not string enumString || string.IsNullOrEmpty(enumString))
{
    return Binding.DoNothing; // graceful fallback instead of throwing
}

Type guard

static bool IsValidConverterParameter(object? p) => p is string s && Enum.GetNames(typeof(Wpf.Ui.Appearance.ApplicationTheme)).Contains(s);

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of lepoco/wpfui@ffebacd610 (2026-08-13). Data as JSON: /api/errors/2221fe0643a4c2b2. Report an issue: GitHub.