{"record":{"id":"7a6f7476580b66a5","repo":"dotnet/wpf","slug":"sr-stylepropertyinstylenotallowed-triggerbase","errorCode":null,"errorMessage":"SR.StylePropertyInStyleNotAllowed","messagePattern":"SR\\.StylePropertyInStyleNotAllowed","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs","lineNumber":177,"sourceCode":"                {\n                    throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, \"trigger\"));\n                }\n\n                _executeExitActionsOnApply = value;\n            }\n        }\n\n*/\n        /// <summary>\n        ///     Parameter validation work common to the SetXXXX methods that deal\n        /// with the container node of the Style/Template.\n        /// </summary>\n        internal void ProcessParametersContainer(DependencyProperty dp)\n        {\n            // Not allowed to use Style to affect the StyleProperty.\n            if (dp == FrameworkElement.StyleProperty)\n            {\n                throw new ArgumentException(SR.StylePropertyInStyleNotAllowed);\n            }\n        }\n\n        /// <summary>\n        ///     Parameter validation work common to the SetXXXX methods that deal\n        /// with visual tree child nodes.\n        /// </summary>\n        internal string ProcessParametersVisualTreeChild(DependencyProperty dp, string target)\n        {\n            ArgumentNullException.ThrowIfNull(target);\n\n            if (target.Length == 0)\n            {\n                throw new ArgumentException(SR.ChildNameMustBeNonEmpty);\n            }\n\n            return String.Intern(target);\n        }","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs#L159-L195","documentation":"TriggerBase.ProcessParametersContainer throws ArgumentException with SR.StylePropertyInStyleNotAllowed when a trigger targets the Style property itself (FrameworkElement.StyleProperty). A style is not allowed to affect its own Style property — it would create self-reference semantics WPF forbids.","triggerScenarios":"Defining a Setter or trigger SetXxx with Property=\"Style\" inside a Style or template, e.g. <Setter Property=\"Style\" .../> within <Style.Triggers> or a PropertyTrigger referencing StyleProperty.","commonSituations":"XAML authoring mistake: trying to swap the control's style from within its own style's triggers; copy-paste of setters across style scopes.","solutions":["Remove the Setter/trigger that targets the Style property from the style","Use a separate parent style or a DataTrigger/StyleSelector to change styles","Target a different property (or use template triggers for visual changes)"],"exampleFix":"// before\n<Trigger Property=\"IsMouseOver\" Value=\"True\">\n  <Setter Property=\"Style\" Value=\"{StaticResource HoverStyle}\"/>\n</Trigger>\n// after\n<!-- change an inner visual property instead -->\n<Trigger Property=\"IsMouseOver\" Value=\"True\">\n  <Setter Property=\"Background\" Value=\"LightBlue\"/>\n</Trigger>","handlingStrategy":"validation","validationCode":"if (setter.Property == FrameworkElement.StyleProperty)\n    throw new ArgumentException(\"A style cannot target its own Style property.\");","typeGuard":"static bool IsAllowedSetterProperty(DependencyProperty dp) => dp != FrameworkElement.StyleProperty;","tryCatchPattern":"try { BuildTriggers(); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Style\")) { /* remove Style-targeting setter */ }","preventionTips":["Never set Property=\"Style\" inside a style's setters/triggers","Change styles from outside via selectors or code-behind","Audit XAML for Property=\"Style\" occurrences"],"tags":["wpf","xaml","styles","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}