dotnet/wpf · error · ArgumentException
Microsoft.Windows.Controls.SR.InvalidKeyTipOffset
Error message
Microsoft.Windows.Controls.SR.InvalidKeyTipOffset
What it means
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.
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
Example fix
// before e.HorizontalOffset = desiredWidth / itemCount; // NaN/Infinity when itemCount == 0 // after double offset = itemCount > 0 ? desiredWidth / itemCount : 0; e.HorizontalOffset = double.IsFinite(offset) ? offset : 0;
Defensive patterns
Strategy: validation
Validate before calling
if (!double.IsFinite(offset)) offset = 0; e.HorizontalOffset = offset;
Type guard
bool IsValidKeyTipOffset(double v) => !double.IsInfinity(v) && !double.IsNaN(v);
Try / catch
try { e.HorizontalOffset = computedOffset; }
catch (ArgumentException) { e.HorizontalOffset = 0; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: Custom key tip positioning logic computing offsets from layout math that divides by zero; uninitialized double fields defaulting and later propagating NaN through calculations.
Related errors
- ArgumentOutOfRangeException(parameterName)
- ArgumentOutOfRangeException(parameterName)
- Microsoft.Windows.Controls.SR.ElementNotKeyTipScope
- Microsoft.Windows.Controls.SR.Format(Microsoft.Windows.Contr…
- SR.ArgumentOutOfRange_Generic_MustBeFinite
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/1e93a38b3c3601b4.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Windows.Controls.Ribbon/Microsoft/Windows/Controls/ActivatingKeyTipEventArgs.cs:86
{
get;
set;
}
/// <summary>
/// Horizontal offset from the defined horizontal placement.
/// </summary>
public double KeyTipHorizontalOffset
{
get
{
return _horizontalOffset;
}
set
{
if (double.IsInfinity(value) || double.IsNaN(value))
{
throw new ArgumentException(Microsoft.Windows.Controls.SR.InvalidKeyTipOffset);
}
_horizontalOffset = value;
}
}
/// <summary>
/// Vertical offset from the defined vertical placement.
/// </summary>
public double KeyTipVerticalOffset
{
get
{
return _verticalOffset;
}
set
{
if (double.IsInfinity(value) || double.IsNaN(value))
{View on GitHub (pinned to 81131a70a4)