{"record":{"id":"d37f87ab050569be","repo":"dotnet/wpf","slug":"sr-eventtriggerdonotsetproperties","errorCode":null,"errorMessage":"SR.EventTriggerDoNotSetProperties","messagePattern":"SR\\.EventTriggerDoNotSetProperties","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/EventTrigger.cs","lineNumber":213,"sourceCode":"\n        /// <summary>\n        /// This method is used by TypeDescriptor to determine if this property should\n        /// be serialized.\n        /// </summary>\n        [EditorBrowsable(EditorBrowsableState.Never)]\n        public bool ShouldSerializeActions()\n        {\n            return ( _actions != null && _actions.Count > 0 );\n        }\n\n        ///////////////////////////////////////////////////////////////////////\n        // Internal members\n        \n        internal sealed override void Seal()\n        {\n            if( PropertyValues.Count > 0 )\n            {\n                throw new InvalidOperationException(SR.EventTriggerDoNotSetProperties);\n            }\n\n            // EnterActions/ExitActions aren't meaningful on event triggers.\n            if( HasEnterActions || HasExitActions )\n            {\n                throw new InvalidOperationException(SR.EventTriggerDoesNotEnterExit);\n            }\n\n            if (_routedEvent != null && _actions != null && _actions.Count > 0)\n            {\n                _actions.Seal(this);  // TriggerActions need a link back to me to fetch the childId corresponding the sourceId string.\n            }\n\n            base.Seal(); // Should be almost a no-op given lack of PropertyValues\n        }\n\n        ///////////////////////////////////////////////////////////////////////\n        // Private members","sourceCodeStart":195,"sourceCodeEnd":231,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/EventTrigger.cs#L195-L231","documentation":"EventTrigger.Seal() throws if the trigger contains Setter values (PropertyValues). Unlike property triggers, EventTriggers run actions in response to routed events and do not apply property setters; the library rejects any configured setters as a usage error.","triggerScenarios":"Adding SetterBase items to EventTrigger via its SetterActions/property-values collection (or declaring <EventTrigger><Setter Property=.../></EventTrigger> in XAML) and then sealing the trigger when the style/template is applied.","commonSituations":"Copying a Trigger's setter syntax into an EventTrigger in XAML; programmatically adding setters to an EventTrigger assuming parity with Trigger/MultiTrigger; migration of legacy style code.","solutions":["Replace setters with EventTrigger Actions (e.g. BeginStoryboard or a TriggerAction-derived class) inside the EventTrigger.","Move property setters to a regular Trigger or use a StateTrigger/VisualStateManager approach for state-based property changes.","If the change should happen in response to an event, use an animation Storyboard targeting the property via BeginStoryboard."],"exampleFix":"<!-- before -->\n<EventTrigger RoutedEvent=\"ButtonBase.Click\">\n  <Setter Property=\"Opacity\" Value=\"0.5\" />\n</EventTrigger>\n\n<!-- after -->\n<EventTrigger RoutedEvent=\"ButtonBase.Click\">\n  <BeginStoryboard>\n    <Storyboard>\n      <DoubleAnimation Storyboard.TargetProperty=\"Opacity\" To=\"0.5\" />\n    </Storyboard>\n  </BeginStoryboard>\n</EventTrigger>","handlingStrategy":"validation","validationCode":"if (eventTrigger.PropertyValues.Count > 0)\n    throw new InvalidOperationException(\"EventTrigger must not contain setters; use Actions instead.\");","typeGuard":null,"tryCatchPattern":"try { trigger.Seal(); }\ncatch (InvalidOperationException) { /* convert setters to BeginStoryboard/TriggerAction */ }","preventionTips":["Remember EventTrigger only supports TriggerAction children (BeginStoryboard etc.), never Setter.","Use property Trigger or VisualStateManager for state-driven property changes.","Validate XAML trigger definitions when migrating between Trigger and EventTrigger."],"tags":["wpf","xaml","unsupported-operation","eventtrigger"],"backgroundTag":"unsupported-operation","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"}