{"record":{"id":"8e327d70c45487bf","repo":"HandyOrg/HandyControl","slug":"the-element-must-be-a-dependencyobject","errorCode":null,"errorMessage":"The element must be a DependencyObject","messagePattern":"The element must be a DependencyObject","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Shared/Microsoft.Windows.Shell/WindowChrome.cs","lineNumber":62,"sourceCode":"    }\n\n    [SuppressMessage(\"Microsoft.Design\", \"CA1011:ConsiderPassingBaseTypesAsParameters\")]\n    [SuppressMessage(\"Microsoft.Design\", \"CA1062:Validate arguments of public methods\", MessageId = \"0\")]\n    public static void SetWindowChrome(Window window, WindowChrome chrome)\n    {\n        Verify.IsNotNull<Window>(window, \"window\");\n        window.SetValue(WindowChrome.WindowChromeProperty, chrome);\n    }\n\n    [SuppressMessage(\"Microsoft.Design\", \"CA1011:ConsiderPassingBaseTypesAsParameters\")]\n    [SuppressMessage(\"Microsoft.Design\", \"CA1062:Validate arguments of public methods\", MessageId = \"0\")]\n    public static bool GetIsHitTestVisibleInChrome(IInputElement inputElement)\n    {\n        Verify.IsNotNull<IInputElement>(inputElement, \"inputElement\");\n        DependencyObject dependencyObject = inputElement as DependencyObject;\n        if (dependencyObject == null)\n        {\n            throw new ArgumentException(\"The element must be a DependencyObject\", \"inputElement\");\n        }\n        return (bool) dependencyObject.GetValue(WindowChrome.IsHitTestVisibleInChromeProperty);\n    }\n\n    [SuppressMessage(\"Microsoft.Design\", \"CA1011:ConsiderPassingBaseTypesAsParameters\")]\n    [SuppressMessage(\"Microsoft.Design\", \"CA1062:Validate arguments of public methods\", MessageId = \"0\")]\n    public static void SetIsHitTestVisibleInChrome(IInputElement inputElement, bool hitTestVisible)\n    {\n        Verify.IsNotNull<IInputElement>(inputElement, \"inputElement\");\n        DependencyObject dependencyObject = inputElement as DependencyObject;\n        if (dependencyObject == null)\n        {\n            throw new ArgumentException(\"The element must be a DependencyObject\", \"inputElement\");\n        }\n        dependencyObject.SetValue(WindowChrome.IsHitTestVisibleInChromeProperty, hitTestVisible);\n    }\n\n    public double CaptionHeight","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/Microsoft.Windows.Shell/WindowChrome.cs#L44-L80","documentation":"WindowChrome.GetIsHitTestVisibleInChrome reads the IsHitTestVisibleInChrome attached property, which requires the element to be a DependencyObject so GetValue can be used. The parameter is typed IInputElement (broader), so a non-DependencyObject implementation throws ArgumentException.","triggerScenarios":"Calling WindowChrome.GetIsHitTestVisibleInChrome with an IInputElement that is not a DependencyObject — i.e. a custom class implementing IInputElement directly rather than deriving from UIElement/ContentElement.","commonSituations":"Custom input elements or mocks implementing IInputElement without inheriting from UIElement; passing test doubles that only implement the interface.","solutions":["Ensure the element derives from System.Windows.UIElement or FrameworkElement (both are DependencyObjects)","Cast and check: if (element is DependencyObject) before calling","Prefer the UIElement overload/usage so the type system enforces this at compile time"],"exampleFix":"// before\nIInputElement el = new CustomInputElement(); // not a DependencyObject\nbool v = WindowChrome.GetIsHitTestVisibleInChrome(el);\n// after\nvar el = new Button(); // any UIElement\nif (el is DependencyObject)\n    bool v = WindowChrome.GetIsHitTestVisibleInChrome(el);","handlingStrategy":"type-guard","validationCode":"if (inputElement is not DependencyObject) throw new ArgumentException(\"Element must derive from DependencyObject (e.g. UIElement)\", nameof(inputElement));","typeGuard":"bool IsChromeCompatible(IInputElement e) => e is DependencyObject;","tryCatchPattern":"try { bool v = WindowChrome.GetIsHitTestVisibleInChrome(el); } catch (ArgumentException) { v = false; /* default for non-DependencyObject */ }","preventionTips":["Type element parameters as UIElement instead of IInputElement","Derive custom input elements from UIElement/FrameworkElement","Avoid IInputElement mocks in tests; use real FrameworkElements"],"tags":["wpf","type-mismatch","windowchrome"],"backgroundTag":"incompatible-source-type","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}