dotnet/wpf · error · ArgumentException
SR.StylePropertyInStyleNotAllowed
Error message
SR.StylePropertyInStyleNotAllowed
What it means
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.
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)
Example fix
// before
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Style" Value="{StaticResource HoverStyle}"/>
</Trigger>
// after
<!-- change an inner visual property instead -->
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Background" Value="LightBlue"/>
</Trigger> Defensive patterns
Strategy: validation
Validate before calling
if (setter.Property == FrameworkElement.StyleProperty)
throw new ArgumentException("A style cannot target its own Style property."); Type guard
static bool IsAllowedSetterProperty(DependencyProperty dp) => dp != FrameworkElement.StyleProperty;
Try / catch
try { BuildTriggers(); }
catch (ArgumentException ex) when (ex.Message.Contains("Style")) { /* remove Style-targeting setter */ } Prevention
- 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
When it happens
Trigger: 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.
Common situations: XAML authoring mistake: trying to swap the control's style from within its own style's triggers; copy-paste of setters across style scopes.
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
- Animation_ChildMustBeKeyFrame
- InvalidEnumArgumentException("value", (int)value…
- SR.CyclicThemeStyleReferenceDetected
- SR.Format(SR.EventTriggerOnStyleNotAllowedToHaveTarget…
- SR.MissingTriggerProperty
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/7a6f7476580b66a5.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/TriggerBase.cs:177
{
throw new InvalidOperationException(SR.Format(SR.CannotChangeAfterSealed, "trigger"));
}
_executeExitActionsOnApply = value;
}
}
*/
/// <summary>
/// Parameter validation work common to the SetXXXX methods that deal
/// with the container node of the Style/Template.
/// </summary>
internal void ProcessParametersContainer(DependencyProperty dp)
{
// Not allowed to use Style to affect the StyleProperty.
if (dp == FrameworkElement.StyleProperty)
{
throw new ArgumentException(SR.StylePropertyInStyleNotAllowed);
}
}
/// <summary>
/// Parameter validation work common to the SetXXXX methods that deal
/// with visual tree child nodes.
/// </summary>
internal string ProcessParametersVisualTreeChild(DependencyProperty dp, string target)
{
ArgumentNullException.ThrowIfNull(target);
if (target.Length == 0)
{
throw new ArgumentException(SR.ChildNameMustBeNonEmpty);
}
return String.Intern(target);
}View on GitHub (pinned to 81131a70a4)