{"record":{"id":"b2e01d6ed9e34d1f","repo":"dotnet/wpf","slug":"sr-format-sr-invalidstickynotetemplate-type-typeof-inkcanvas","errorCode":null,"errorMessage":"SR.Format(SR.InvalidStickyNoteTemplate, type, typeof(InkCanvas), SNBConstants.c_ContentControlId)","messagePattern":"SR\\.Format\\(SR\\.InvalidStickyNoteTemplate, type, typeof\\(InkCanvas\\), SNBConstants\\.c_ContentControlId\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteContentControl.cs","lineNumber":485,"sourceCode":"        {\n            StickyNoteContentControl contentControl = null;\n\n            switch (type)\n            {\n                case StickyNoteType.Text:\n                    {\n                        RichTextBox rtb = content as RichTextBox;\n                        if (rtb == null)\n                            throw new InvalidOperationException(SR.Format(SR.InvalidStickyNoteTemplate, type, typeof(RichTextBox), SNBConstants.c_ContentControlId));\n\n                        contentControl = new StickyNoteRichTextBox(rtb);\n                        break;\n                    }\n                case StickyNoteType.Ink:\n                    {\n                        InkCanvas canvas = content as InkCanvas;\n                        if (canvas == null)\n                            throw new InvalidOperationException(SR.Format(SR.InvalidStickyNoteTemplate, type, typeof(InkCanvas), SNBConstants.c_ContentControlId));\n\n                        contentControl = new StickyNoteInkCanvas(canvas);\n                        break;\n                    }\n            }\n\n            return contentControl;\n        }\n\n        #endregion Public Methods\n    }\n}\n","sourceCodeStart":467,"sourceCodeEnd":498,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/MS/Internal/Controls/StickyNote/StickyNoteContentControl.cs#L467-L498","documentation":"Same mismatch as the Text case, but for ink notes: the StickyNote Ink template expects the content to be exactly an InkCanvas. CreateContentControl throws InvalidOperationException when content of an ink-note template is not an InkCanvas.","triggerScenarios":"Applying a StickyNoteType.Ink template (or calling CreateContentControl) when the Content is any control other than InkCanvas, e.g. a RichTextBox or custom canvas.","commonSituations":"Swapping Text and Ink StickyNote templates without changing the content control; custom templates using derived-but-not-InkCanvas content; dynamic template switching at runtime.","solutions":["Set the ink note's content to a genuine InkCanvas instance","Use StickyNoteType.Text with a RichTextBox for text content","Verify the template's content control carrying SNBConstants.c_ContentControlId contains an InkCanvas"],"exampleFix":"// before\nstickyNote.Content = new RichTextBox();\n// after\nstickyNote.Content = new InkCanvas();","handlingStrategy":"type-guard","validationCode":"if (stickyNote.Content is not InkCanvas) throw new InvalidOperationException(\"StickyNote ink template requires an InkCanvas content\");","typeGuard":"bool IsValidInkNoteContent(object c) => c is InkCanvas;","tryCatchPattern":"try { CreateContentControl(StickyNoteType.Ink, content); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"template\")) { /* substitute InkCanvas or log */ }","preventionTips":["Always pair StickyNoteType.Ink with InkCanvas content","When switching templates, also swap the content control type","Unit-test template/content pairing for both note types"],"tags":["wpf","invalid-content-type","stickynote"],"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-21T21:30:21.729Z"}