{"record":{"id":"1e93a38b3c3601b4","repo":"dotnet/wpf","slug":"microsoft-windows-controls-sr-invalidkeytipoffset","errorCode":null,"errorMessage":"Microsoft.Windows.Controls.SR.InvalidKeyTipOffset","messagePattern":"Microsoft\\.Windows\\.Controls\\.SR\\.InvalidKeyTipOffset","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/ActivatingKeyTipEventArgs.cs","lineNumber":86,"sourceCode":"        {\n            get;\n            set;\n        }\n\n        /// <summary>\n        ///     Horizontal offset from the defined horizontal placement.\n        /// </summary>\n        public double KeyTipHorizontalOffset\n        {\n            get\n            {\n                return _horizontalOffset;\n            }\n            set\n            {\n                if (double.IsInfinity(value) || double.IsNaN(value))\n                {\n                    throw new ArgumentException(Microsoft.Windows.Controls.SR.InvalidKeyTipOffset);\n                }\n                _horizontalOffset = value;\n            }\n        }\n\n        /// <summary>\n        ///     Vertical offset from the defined vertical placement.\n        /// </summary>\n        public double KeyTipVerticalOffset\n        {\n            get\n            {\n                return _verticalOffset;\n            }\n            set\n            {\n                if (double.IsInfinity(value) || double.IsNaN(value))\n                {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/ActivatingKeyTipEventArgs.cs#L68-L104","documentation":"ActivatingKeyTipEventArgs.HorizontalOffset validates its value: the key tip offset must be a finite number. Setting it to double.PositiveInfinity, double.NegativeInfinity, or double.NaN throws ArgumentException with SR.InvalidKeyTipOffset, because the KeyTipService cannot position the key tip with a non-finite offset.","triggerScenarios":"In a KeyTipActivating / ActivatingKeyTipEventArgs handler (or code computing the offset), assigning HorizontalOffset a value that is Infinity or NaN — often from a division by zero or an unset computed position.","commonSituations":"Custom key tip positioning logic computing offsets from layout math that divides by zero; uninitialized double fields defaulting and later propagating NaN through calculations.","solutions":["Validate the computed offset with double.IsFinite before assigning it to HorizontalOffset","Fix the upstream calculation producing Infinity/NaN (e.g. guard division by zero, check layout size of 0)","Clamp the offset to a sane fallback value (e.g. 0) when the computation fails","Catch ArgumentException in the key tip handler and substitute a default offset"],"exampleFix":"// before\ne.HorizontalOffset = desiredWidth / itemCount; // NaN/Infinity when itemCount == 0\n// after\ndouble offset = itemCount > 0 ? desiredWidth / itemCount : 0;\ne.HorizontalOffset = double.IsFinite(offset) ? offset : 0;","handlingStrategy":"validation","validationCode":"if (!double.IsFinite(offset)) offset = 0;\ne.HorizontalOffset = offset;","typeGuard":"bool IsValidKeyTipOffset(double v) => !double.IsInfinity(v) && !double.IsNaN(v);\n","tryCatchPattern":"try { e.HorizontalOffset = computedOffset; }\ncatch (ArgumentException) { e.HorizontalOffset = 0; }","preventionTips":["Run double.IsFinite on all computed offsets before assignment","Guard divisions used in key tip position math","Verify layout has completed before computing screen coordinates","Clamp out-of-range layout results to safe defaults"],"tags":["wpf","ribbon","keytips","argumentoutofrange","nan"],"backgroundTag":"argument-out-of-range","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}