dotnet/wpf · error · ArgumentException

SR.InvalidSttValue

Error message

SR.InvalidSttValue

What it means

DrawingAttributes.StylusTipTransform setter throws ArgumentException with SR.InvalidSttValue when the assigned Matrix has a non-zero OffsetX or OffsetY. StylusTipTransform is a transform applied around the stylus tip origin, so translation components are meaningless and rejected; only rotation/scale/skew matrices are accepted. Validation of the matrix structure itself is deferred to the underlying ExtendedPropertyCollection.

Solutions

  1. Zero out OffsetX and OffsetY before assigning: m.OffsetX = 0; m.OffsetY = 0;
  2. Build the matrix only from Rotate/Scale/Skew transforms (never TranslateTransform).
  3. If translation is needed, apply it elsewhere (e.g. positioning the ink canvas), not in StylusTipTransform.

Example fix

// before
var m = new Matrix(1, 0, 0, 1, 10, 20);
da.StylusTipTransform = m; // ArgumentException
// after
var m = new Matrix(1, 0, 0, 1, 0, 0);
da.StylusTipTransform = m; // or set m.OffsetX = m.OffsetY = 0 first
Defensive patterns

Strategy: validation

Validate before calling

bool IsStylusTipTransformLegal(Matrix m) => m.OffsetX == 0 && m.OffsetY == 0;
// before assigning:
// if (!IsStylusTipTransformLegal(m)) m.OffsetX = m.OffsetY = 0;

Type guard

static bool HasNoTranslation(Matrix m) => m.OffsetX == 0 && m.OffsetY == 0;

Try / catch

try { da.StylusTipTransform = m; }
catch (ArgumentException) { m.OffsetX = 0; m.OffsetY = 0; da.StylusTipTransform = m; }

Prevention

When it happens

Trigger: Assigning a Matrix built with translation, e.g. new Matrix(1,0,0,1, 10, 20) or one obtained from a TranslateTransform, to DrawingAttributes.StylusTipTransform.

Common situations: Developers copy a Matrix from a RenderTransform (which commonly includes translation offsets) and reuse it for StylusTipTransform; composing transforms with TranslateTransform before converting to Matrix.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/228ff15a8b4f850b. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Ink/DrawingAttributes.cs:133

        /// </summary>
        public Matrix StylusTipTransform
        {
            get
            {
                //prevent boxing / unboxing if possible
                if (!_extendedProperties.Contains(KnownIds.StylusTipTransform))
                {
                    Debug.Assert(Matrix.Identity == (Matrix)GetDefaultDrawingAttributeValue(KnownIds.StylusTipTransform));
                    return Matrix.Identity;
                }
                return (Matrix)GetExtendedPropertyBackedProperty(KnownIds.StylusTipTransform);
            }
            set
            {
                Matrix m = (Matrix) value;
                if (m.OffsetX != 0 || m.OffsetY != 0)
                {
                    throw new ArgumentException(SR.InvalidSttValue, nameof(value));
                }
                //no need to raise change events, they will bubble up from the EPC
                //underneath us
                // Validation of value is done in EPC
                SetExtendedPropertyBackedProperty(KnownIds.StylusTipTransform, value);
            }
        }

        /// <summary>
        /// The height of the StylusTip
        /// </summary>
        public double Height
        {
            get
            {
                //prevent boxing / unboxing if possible
                if (!_extendedProperties.Contains(KnownIds.StylusHeight))
                {

View on GitHub (pinned to 81131a70a4)