{"record":{"id":"ba97d141cbcc4ab8","repo":"dotnet/wpf","slug":"sr-invalidinkforeground","errorCode":null,"errorMessage":"SR.InvalidInkForeground","messagePattern":"SR\\.InvalidInkForeground","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/StickyNote.cs","lineNumber":1741,"sourceCode":"        /// <summary>\n        /// Update DrawingAttributes on InkCanvas\n        /// </summary>\n        private void UpdateInkDrawingAttributes()\n        {\n            if ( Content == null || Content.Type != StickyNoteType.Ink )\n            {\n                // Return now if there is no InkCanvas.\n                return;\n            }\n\n            DrawingAttributes da = new DrawingAttributes();\n\n            SolidColorBrush foreground = Foreground as SolidColorBrush;\n\n            // Make sure the foreground is type of SolidColorBrush.\n            if ( foreground == null )\n            {\n                throw new ArgumentException(SR.InvalidInkForeground);\n            }\n\n            da.StylusTip = StylusTip.Ellipse;\n            da.Width = PenWidth;\n            da.Height = PenWidth;\n            da.Color = foreground.Color;\n\n            // Update the DA on InkCanvas.\n            ( (InkCanvas)( Content.InnerControl ) ).DefaultDrawingAttributes = da;\n        }\n\n        #endregion // Private Methods\n\n        //-------------------------------------------------------------------------------\n        //\n        // Private Properties\n        //\n        //-------------------------------------------------------------------------------","sourceCodeStart":1723,"sourceCodeEnd":1759,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Controls/StickyNote.cs#L1723-L1759","documentation":"StickyNoteControl throws ArgumentException when building its ink DrawingAttributes because the control's Foreground property is not a SolidColorBrush. Ink drawing requires a solid color to set DrawingAttributes.Color; gradients or other brushes have no single color to use.","triggerScenarios":"Setting Foreground on a StickyNoteControl (or its theme/style) to a non-SolidColorBrush such as LinearGradientBrush, RadialGradientBrush, ImageBrush, or DynamicResource resolving to such a brush, then entering ink mode which calls the code that reads Foreground.","commonSituations":"Applying a global style with gradient foreground brushes; inheriting Foreground from a parent that uses a gradient; binding Foreground to a theme resource that is not solid.","solutions":["Set StickyNoteControl.Foreground to a SolidColorBrush (e.g. new SolidColorBrush(Colors.Black)).","If a dynamic brush is used, ensure it resolves to a SolidColorBrush at runtime.","Wrap or convert other brush types to a solid color before assigning."],"exampleFix":"// before\nstickyNote.Foreground = new LinearGradientBrush(Colors.Black, Colors.Gray, 90);\n// after\nstickyNote.Foreground = new SolidColorBrush(Colors.Black);","handlingStrategy":"type-guard","validationCode":"if ((stickyNote.Foreground as SolidColorBrush) == null)\n    stickyNote.Foreground = new SolidColorBrush(Colors.Black);","typeGuard":"static bool HasSolidForeground(Control c) => c.Foreground is SolidColorBrush;","tryCatchPattern":"try { EnableInk(stickyNote); }\ncatch (ArgumentException) { stickyNote.Foreground = new SolidColorBrush(Colors.Black); EnableInk(stickyNote); }","preventionTips":["Always assign SolidColorBrush to ink-capable controls","Audit styles/themes for gradient foreground brushes","Convert any brush to a representative solid color before assigning"],"tags":["wpf","ink","argument-exception","brush"],"backgroundTag":"type-mismatch","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"}