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
- Only set AutoWatermark on supported types: TextBox, ComboBox, NumericUpDown, HotKeyBox, DatePicker, TimePicker, DateTimePicker, ColorPicker, ColorCanvas, MultiSelectionComboBox.
- For unsupported controls (e.g. PasswordBox), set the Watermark property directly instead.
- Remove AutoWatermark from controls not in the mapping.
- 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
- Set AutoWatermark only on the supported control types.
- For PasswordBox and other unsupported controls, set Watermark directly.
- Audit forms for stray AutoWatermark usage on unsupported controls.
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
- The property 'IsSpellCheckContextMenuEnabled' may only be se
- The inverse Flyout theme only works if the window theme abid
- The Dark Flyout theme only works if the window theme abides
- The Light Flyout theme only works if the window theme abides
- The property 'SelectedItems' may only be set on ListBox, Mul
AI-assisted analysis of MahApps/MahApps.Metro@72099e310b (2026-08-13).
Data as JSON: /api/errors/35cb03e95bac9d20.
Report an issue: GitHub.