{"record":{"id":"ca85de373c8daf70","repo":"dotnet/maui","slug":"the-element-must-be-a-dependencyobject","errorCode":null,"errorMessage":"The element must be a DependencyObject","messagePattern":"The element must be a DependencyObject","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/WindowChrome.cs","lineNumber":124,"sourceCode":"\t\t\tVerify.IsNotNull(window, \"window\");\n\t\t\twindow.SetValue(WindowChromeProperty, chrome);\n\t\t}\n\n\t\tpublic static readonly DependencyProperty IsHitTestVisibleInChromeProperty = DependencyProperty.RegisterAttached(\n\t\t\t\"IsHitTestVisibleInChrome\",\n\t\t\ttypeof(bool),\n\t\t\ttypeof(WindowChrome),\n\t\t\tnew FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits));\n\n\t\t[SuppressMessage(\"Microsoft.Design\", \"CA1062:Validate arguments of public methods\", MessageId = \"0\")]\n\t\t[SuppressMessage(\"Microsoft.Design\", \"CA1011:ConsiderPassingBaseTypesAsParameters\")]\n\t\tpublic static bool GetIsHitTestVisibleInChrome(IInputElement inputElement)\n\t\t{\n\t\t\tVerify.IsNotNull(inputElement, \"inputElement\");\n\t\t\tvar dobj = inputElement as DependencyObject;\n\t\t\tif (dobj == null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentException(\"The element must be a DependencyObject\", \"inputElement\");\n\t\t\t}\n\t\t\treturn (bool)dobj.GetValue(IsHitTestVisibleInChromeProperty);\n\t\t}\n\n\t\t[SuppressMessage(\"Microsoft.Design\", \"CA1062:Validate arguments of public methods\", MessageId = \"0\")]\n\t\t[SuppressMessage(\"Microsoft.Design\", \"CA1011:ConsiderPassingBaseTypesAsParameters\")]\n\t\tpublic static void SetIsHitTestVisibleInChrome(IInputElement inputElement, bool hitTestVisible)\n\t\t{\n\t\t\tVerify.IsNotNull(inputElement, \"inputElement\");\n\t\t\tvar dobj = inputElement as DependencyObject;\n\t\t\tif (dobj == null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentException(\"The element must be a DependencyObject\", \"inputElement\");\n\t\t\t}\n\t\t\tdobj.SetValue(IsHitTestVisibleInChromeProperty, hitTestVisible);\n\t\t}\n\n\t\tpublic static readonly DependencyProperty ResizeGripDirectionProperty = DependencyProperty.RegisterAttached(","sourceCodeStart":106,"sourceCodeEnd":142,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Compatibility/Core/src/WPF/Microsoft.Windows.Shell/WindowChrome.cs#L106-L142","documentation":"WindowChrome.GetIsHitTestVisibleInChrome throws ArgumentException when the IInputElement passed in cannot be cast to DependencyObject. The attached property IsHitTestVisibleInChrome is stored on DependencyObject, so a non-DependencyObject input cannot carry the property value. The null check is done first via Verify.IsNotNull.","triggerScenarios":"Calling WindowChrome.GetIsHitTestVisibleInChrome(inputElement) with an IInputElement implementation that is not a DependencyObject — e.g. a custom IInputElement wrapper, a third-party input element, or a mock that does not derive from DependencyObject.","commonSituations":"Passing a custom IInputElement that wraps a UIElement but is not itself a DependencyObject; test doubles; interop with non-WPF input element implementations; confusion between raw IInputElement and the WPF UIElement hierarchy.","solutions":["Pass a DependencyObject-derived element (UIElement, FrameworkElement, ContentElement, etc.).","Type-check before calling: if (inputElement is DependencyObject) before Get/Set.","If you hold a UIElement, pass it directly rather than wrapping it."],"exampleFix":"// before\nvar visible = WindowChrome.GetIsHitTestVisibleInChrome(customInputElement);\n\n// after\nif (inputElement is DependencyObject dob)\n{\n    var visible = WindowChrome.GetIsHitTestVisibleInChrome(dob);\n}\nelse\n{\n    throw new ArgumentException(\"Element must be a DependencyObject.\", nameof(inputElement));\n}","handlingStrategy":"type-guard","validationCode":"// Pre-check: element must be a DependencyObject\nif (inputElement is not DependencyObject)\n{\n    throw new ArgumentException(\"Element must be a DependencyObject.\", nameof(inputElement));\n}\nvar visible = WindowChrome.GetIsHitTestVisibleInChrome(inputElement);","typeGuard":"static bool IsDependencyObject(IInputElement element)\n{\n    return element is DependencyObject;\n}","tryCatchPattern":null,"preventionTips":["Pass UIElement/FrameworkElement directly rather than wrapping IInputElement.","Pattern-match with 'is DependencyObject' before calling attached-property getters.","Avoid custom IInputElement implementations unless they derive from DependencyObject."],"tags":["wpf","dependency-object","argument","window-chrome","attached-property"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}