MahApps/MahApps.Metro · error · NotSupportedException

{nameof(AutoWatermarkProperty)} is not supported for {fe.Get

Error message

{nameof(AutoWatermarkProperty)} is not supported for {fe.GetType()}

What it means

Thrown by OnControlWithAutoWatermarkSupportLoaded when the loaded element's type is not in AutoWatermarkPropertyMapping. The mapping covers TextBox, ComboBox, NumericUpDown, HotKeyBox, DatePicker, TimePicker, DateTimePicker, ColorPicker, ColorCanvas, and MultiSelectionComboBox. Setting TextBoxHelper.AutoWatermark=true on any other control type throws NotSupportedException at load time because there is no target DependencyProperty to read a [Display] attribute from.

Source

Thrown at src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs:302

                        element.Loaded += OnControlWithAutoWatermarkSupportLoaded;
                    }
                }
                else
                {
                    element.Loaded -= OnControlWithAutoWatermarkSupportLoaded;
                }
            }
        }

        private static void OnControlWithAutoWatermarkSupportLoaded(object o, RoutedEventArgs routedEventArgs)
        {
            if (o is FrameworkElement fe)
            {
                fe.Loaded -= OnControlWithAutoWatermarkSupportLoaded;

                if (!AutoWatermarkPropertyMapping.TryGetValue(fe.GetType(), out var dependencyProperty))
                {
                    throw new NotSupportedException($"{nameof(AutoWatermarkProperty)} is not supported for {fe.GetType()}");
                }

                var resolvedProperty = ResolvePropertyFromBindingExpression(fe.GetBindingExpression(dependencyProperty));
                if (resolvedProperty != null)
                {
                    var attribute = resolvedProperty.GetCustomAttribute<DisplayAttribute>();
                    if (attribute != null)
                    {
                        fe.SetCurrentValue(WatermarkProperty, attribute.GetPrompt());
                    }
                }
            }
        }

        private static PropertyInfo? ResolvePropertyFromBindingExpression(BindingExpression? bindingExpression)
        {
            if (bindingExpression != null && bindingExpression.Status != BindingStatus.PathError)
            {

View on GitHub (pinned to 72099e310b)

Solutions

  1. Only set AutoWatermark on supported types: TextBox, ComboBox, NumericUpDown, HotKeyBox, DatePicker, TimePicker, DateTimePicker, ColorPicker, ColorCanvas, MultiSelectionComboBox.
  2. For unsupported controls (e.g. PasswordBox), set the Watermark property directly instead.
  3. Remove AutoWatermark from controls not in the mapping.
  4. For a custom control, extend AutoWatermarkPropertyMapping (internal) or set Watermark manually.

Example fix

<!-- before -->
<PasswordBox TextBoxHelper.AutoWatermark="True" /> <!-- throws on load -->

<!-- after -->
<PasswordBox TextBoxHelper.Watermark="Enter password" />
Defensive patterns

Strategy: type-guard

Validate before calling

private static readonly HashSet<Type> AutoWatermarkSupported = new()
{
    typeof(TextBox), typeof(ComboBox), typeof(NumericUpDown), typeof(HotKeyBox),
    typeof(DatePicker), typeof(TimePicker), typeof(DateTimePicker),
    typeof(ColorPicker), typeof(ColorCanvas), typeof(MultiSelectionComboBox)
};

if (!AutoWatermarkSupported.Contains(fe.GetType()))
{
    // do not set AutoWatermark; use Watermark directly
}

Type guard

static bool SupportsAutoWatermark(FrameworkElement fe)
    => fe is TextBox or ComboBox or NumericUpDown or HotKeyBox
       or DatePicker or TimePicker or DateTimePicker
       or ColorPicker or ColorCanvas or MultiSelectionComboBox;

Prevention

When it happens

Trigger: Setting AutoWatermark="True" on an unsupported control (e.g. PasswordBox, CheckBox, RadioButton, RichTextBox, or a custom control); using AutoWatermark on a control whose bound property isn't in the mapping.

Common situations: Applying AutoWatermark broadly across a form including controls it doesn't support (PasswordBox is a common miss); expecting AutoWatermark on a third-party control.

Related errors


AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13). Data as JSON: /api/errors/35cb03e95bac9d20. Report an issue: GitHub.