{"record":{"id":"35cb03e95bac9d20","repo":"MahApps/MahApps.Metro","slug":"nameof-autowatermarkproperty-is-not-supported-f","errorCode":null,"errorMessage":"{nameof(AutoWatermarkProperty)} is not supported for {fe.GetType()}","messagePattern":"(.+?) is not supported for (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs","lineNumber":302,"sourceCode":"                        element.Loaded += OnControlWithAutoWatermarkSupportLoaded;\n                    }\n                }\n                else\n                {\n                    element.Loaded -= OnControlWithAutoWatermarkSupportLoaded;\n                }\n            }\n        }\n\n        private static void OnControlWithAutoWatermarkSupportLoaded(object o, RoutedEventArgs routedEventArgs)\n        {\n            if (o is FrameworkElement fe)\n            {\n                fe.Loaded -= OnControlWithAutoWatermarkSupportLoaded;\n\n                if (!AutoWatermarkPropertyMapping.TryGetValue(fe.GetType(), out var dependencyProperty))\n                {\n                    throw new NotSupportedException($\"{nameof(AutoWatermarkProperty)} is not supported for {fe.GetType()}\");\n                }\n\n                var resolvedProperty = ResolvePropertyFromBindingExpression(fe.GetBindingExpression(dependencyProperty));\n                if (resolvedProperty != null)\n                {\n                    var attribute = resolvedProperty.GetCustomAttribute<DisplayAttribute>();\n                    if (attribute != null)\n                    {\n                        fe.SetCurrentValue(WatermarkProperty, attribute.GetPrompt());\n                    }\n                }\n            }\n        }\n\n        private static PropertyInfo? ResolvePropertyFromBindingExpression(BindingExpression? bindingExpression)\n        {\n            if (bindingExpression != null && bindingExpression.Status != BindingStatus.PathError)\n            {","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/MahApps/MahApps.Metro/blob/72099e310bac2d12ac98fd7560b69679252519f5/src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs#L284-L320","documentation":"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.","triggerScenarios":"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.","commonSituations":"Applying AutoWatermark broadly across a form including controls it doesn't support (PasswordBox is a common miss); expecting AutoWatermark on a third-party control.","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."],"exampleFix":"<!-- before -->\n<PasswordBox TextBoxHelper.AutoWatermark=\"True\" /> <!-- throws on load -->\n\n<!-- after -->\n<PasswordBox TextBoxHelper.Watermark=\"Enter password\" />","handlingStrategy":"type-guard","validationCode":"private static readonly HashSet<Type> AutoWatermarkSupported = new()\n{\n    typeof(TextBox), typeof(ComboBox), typeof(NumericUpDown), typeof(HotKeyBox),\n    typeof(DatePicker), typeof(TimePicker), typeof(DateTimePicker),\n    typeof(ColorPicker), typeof(ColorCanvas), typeof(MultiSelectionComboBox)\n};\n\nif (!AutoWatermarkSupported.Contains(fe.GetType()))\n{\n    // do not set AutoWatermark; use Watermark directly\n}","typeGuard":"static bool SupportsAutoWatermark(FrameworkElement fe)\n    => fe is TextBox or ComboBox or NumericUpDown or HotKeyBox\n       or DatePicker or TimePicker or DateTimePicker\n       or ColorPicker or ColorCanvas or MultiSelectionComboBox;","tryCatchPattern":null,"preventionTips":["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."],"tags":["wpf","textbox-helper","mahapps","watermark","type-guard","configuration"],"backgroundTag":null,"analyzedSha":"72099e310bac2d12ac98fd7560b69679252519f5","analyzedAt":"2026-08-13T20:19:34.419Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}