{"record":{"id":"57d5fe551743093b","repo":"dotnet/wpf","slug":"sr-format-sr-invalid-iinputelement-stylusover-gettype-57d5fe","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/Wisp/WispStylusDevice.cs","lineNumber":436,"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 uie3D)\n                {\n                    uie3D.IsEnabledChanged += _overIsEnabledChangedEventHandler;\n                    uie3D.IsVisibleChanged += _overIsVisibleChangedEventHandler;\n                    uie3D.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            if (_stylusOver != null)\n            {\n                o = _stylusOver as DependencyObject;\n                o.SetValue(UIElement.IsStylusDirectlyOverPropertyKey, true); // Same property for ContentElements","sourceCodeStart":418,"sourceCodeEnd":454,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Input/Stylus/Wisp/WispStylusDevice.cs#L418-L454","documentation":"WispStylusDevice.UpdateOverProperty (WispStylusDevice.cs:436) throws InvalidOperationException(SR.Invalid_IInputElement) when attaching IsEnabledChanged/IsVisibleChanged/IsHitTestVisibleChanged handlers to the new _stylusOver element, which is not a UIElement, ContentElement, or UIElement3D. Mirrors error 700/706 for the WispStylusDevice over-property path.","triggerScenarios":"ChangeStylusOver sets a new over element that is not one of the three supported input element classes; the else branch of the pattern match throws while wiring the property-change handlers.","commonSituations":"Custom IInputElement-based controls under the pointer; broken hit-test results returning unsupported elements; version/framework interop where a custom element type slips into stylus state.","solutions":["Make hit-testable elements derive from UIElement, ContentElement, or UIElement3D.","Trace _stylusOver.GetType() to find which component created the element.","Validate InputElement.IsValid on elements before they enter the stylus input path."],"exampleFix":"// before\npublic class Hotspot : FrameworkElement, IInputElement { /* ok */ }\npublic class Hotspot2 : DependencyObject, IInputElement { /* throws */ }\n// after\npublic class Hotspot2 : UIElement { }","handlingStrategy":"type-guard","validationCode":"static bool TracksStylusOver(object e) => e is UIElement || e is ContentElement || e is UIElement3D;","typeGuard":"static bool IsValidInputElement(IInputElement e) => e is UIElement || e is ContentElement || e is UIElement3D;","tryCatchPattern":"try { /* change stylus over */ } catch (InvalidOperationException ex) when (ex.Message.Contains(\"IInputElement\")) { /* log offending type and reset stylus over state */ }","preventionTips":["Test stylus-over behavior with custom controls before shipping","Derive custom input controls from supported base classes","Audit hit-test callbacks for non-standard element types"],"tags":["wpf","stylus","invalidoperation","hit-testing"],"backgroundTag":"incompatible-source-type","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"}