{"record":{"id":"371dacc2b9d22d95","repo":"dotnet/wpf","slug":"sr-format-sr-invalid-iinputelement-stylusover-gettype","errorCode":null,"errorMessage":"SR.Format(SR.Invalid_IInputElement, _stylusOver.GetType())","messagePattern":"SR\\.Format\\(SR\\.Invalid_IInputElement, _stylusOver\\.GetType\\(\\)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerLogic.cs","lineNumber":655,"sourceCode":"                    }\n                    else if (o is ContentElement ce)\n                    {\n                        ce.IsEnabledChanged += _overIsEnabledChangedEventHandler;\n\n                        // NOTE: there are no IsVisible or IsHitTestVisible properties for ContentElements.\n                        //\n                        // ce.IsVisibleChanged += _overIsVisibleChangedEventHandler;\n                        // ce.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler;\n                    }\n                    else if (o is UIElement3D element3D)\n                    {\n                        element3D.IsEnabledChanged += _overIsEnabledChangedEventHandler;\n                        element3D.IsVisibleChanged += _overIsVisibleChangedEventHandler;\n                        element3D.IsHitTestVisibleChanged += _overIsHitTestVisibleChangedEventHandler;\n                    }\n                    else\n                    {\n                        throw new InvalidOperationException(SR.Format(SR.Invalid_IInputElement, _stylusOver.GetType())); \n                    }\n                }\n\n                // Oddly enough, update the IsStylusOver property first.  This is\n                // so any callbacks will see the more-common IsStylusOver property\n                // set correctly.\n                UIElement.StylusOverProperty.OnOriginValueChanged(oldOver as DependencyObject, _stylusOver as DependencyObject, ref _stylusOverTreeState);\n\n                // Invalidate the IsStylusDirectlyOver property.\n                if (oldOver != null)\n                {\n                    o = oldOver as DependencyObject;\n                    o.SetValue(UIElement.IsStylusDirectlyOverPropertyKey, false); // Same property for ContentElements\n                }\n\n                if (_stylusOver != null)\n                {\n                    o = _stylusOver as DependencyObject;","sourceCodeStart":637,"sourceCodeEnd":673,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Pointer/PointerLogic.cs#L637-L673","documentation":"In UpdateOverProperty, when subscribing stylus-over handlers on the NEW over element (_stylusOver), an InvalidOperationException (SR.Invalid_IInputElement with _stylusOver.GetType()) is thrown if the element is not UIElement, ContentElement, or UIElement3D.","triggerScenarios":"Stylus pointer moving over an element that is a DependencyObject/IInputElement but not one of the three supported WPF element types, during over-property update.","commonSituations":"Hovering over custom controls implementing IInputElement directly; plugin visual systems integrated into the WPF tree without inheriting supported base classes.","solutions":["Make hover-sensitive custom elements inherit UIElement (or ContentElement/UIElement3D)","Avoid implementing IInputElement on plain DependencyObjects that participate in stylus input","Verify hit-test targets are supported types in input handling code"],"exampleFix":"// before\nclass MyHoverTarget : DependencyObject, IInputElement { ... }\n// after\nclass MyHoverTarget : UIElement { ... }","handlingStrategy":"type-guard","validationCode":"if (!(hoverTarget is UIElement || hoverTarget is ContentElement || hoverTarget is UIElement3D)) return;","typeGuard":"static bool IsSupportedInputElement(IInputElement e) => e is UIElement || e is ContentElement || e is UIElement3D;","tryCatchPattern":"try { RegisterStylusOver(hoverTarget); }\ncatch (InvalidOperationException) { /* ignore or log unsupported hover target */ }","preventionTips":["Make hover-reactive custom controls inherit UIElement","Avoid direct IInputElement implementations in the stylus input path"],"tags":["wpf","stylus","pointer","invalid-operation"],"backgroundTag":"invalid-state-transition","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}