{"record":{"id":"581441f3da5e1950","repo":"dotnet/wpf","slug":"sr-sourcenamenotsupportedfordatatriggers","errorCode":null,"errorMessage":"SR.SourceNameNotSupportedForDataTriggers","messagePattern":"SR\\.SourceNameNotSupportedForDataTriggers","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MultiDataTrigger.cs","lineNumber":109,"sourceCode":"            }\n\n            // Process the _setters collection: Copy values into PropertyValueList and seal the Setter objects.\n            ProcessSettersCollection(_setters);\n\n            if (_conditions.Count > 0)\n            {\n                // Seal conditions\n                _conditions.Seal(ValueLookupType.DataTrigger);\n            }\n\n            // Build conditions array from collection\n            TriggerConditions = new TriggerCondition[_conditions.Count];\n\n            for (int i = 0; i < TriggerConditions.Length; ++i)\n            {\n                if (_conditions[i].SourceName != null && _conditions[i].SourceName.Length > 0)\n                {\n                    throw new InvalidOperationException(SR.SourceNameNotSupportedForDataTriggers);\n                }\n\n                TriggerConditions[i] = new TriggerCondition(\n                    _conditions[i].Binding,\n                    LogicalOp.Equals,\n                    _conditions[i].Value);\n            }\n\n            // Set conditions array for all property triggers\n            for (int i = 0; i < PropertyValues.Count; ++i)\n            {\n                PropertyValue propertyValue = PropertyValues[i];\n                propertyValue.Conditions = TriggerConditions;\n                switch (propertyValue.ValueType)\n                {\n                    case PropertyValueType.Trigger:\n                        propertyValue.ValueType = PropertyValueType.DataTrigger;\n                        break;","sourceCodeStart":91,"sourceCodeEnd":127,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MultiDataTrigger.cs#L91-L127","documentation":"MultiDataTrigger seals itself when its containing style/template is applied. During Seal(), each condition is checked and any condition with a SourceName set is rejected, because SourceName (element targeting) only makes sense for property triggers on named elements, not for data triggers that evaluate bound data. WPF throws InvalidOperationException to signal the trigger is configured in an unsupported way.","triggerScenarios":"Declaring a <MultiDataTrigger> (or adding via Conditions collection in code) whose Condition has SourceName set, e.g. <Condition SourceName=\"btn\" Binding=\"...\" .../>, then applying the style/template, which invokes MultiDataTrigger.Seal() at line 107-109.","commonSituations":"Copying a MultiTrigger condition into a MultiDataTrigger and forgetting to remove SourceName; hand-editing XAML converted from a MultiTrigger; tool-generated styles that emit SourceName unconditionally.","solutions":["Remove the SourceName attribute from every Condition inside the MultiDataTrigger","If element targeting is needed, use MultiTrigger with property conditions instead of MultiDataTrigger","In code, do not set Condition.SourceName on conditions added to a MultiDataTrigger's Conditions collection"],"exampleFix":"<!-- before -->\n<MultiDataTrigger>\n  <Condition SourceName=\"okButton\" Binding=\"{Binding IsReady}\" Value=\"True\"/>\n</MultiDataTrigger>\n<!-- after -->\n<MultiDataTrigger>\n  <Condition Binding=\"{Binding IsReady}\" Value=\"True\"/>\n</MultiDataTrigger>","handlingStrategy":"validation","validationCode":"// before applying the style\nbool ok = multiDataTrigger.Conditions.Cast<Condition>().All(c => string.IsNullOrEmpty(c.SourceName));\nif (!ok) throw new InvalidOperationException(\"MultiDataTrigger conditions must not set SourceName\");","typeGuard":"static bool IsValidDataTriggerCondition(Condition c) =>\n    c != null && string.IsNullOrEmpty(c.SourceName);","tryCatchPattern":null,"preventionTips":["Never copy SourceName from MultiTrigger conditions into MultiDataTrigger conditions","Validate all Conditions before assigning the style to a control","Prefer bindings on view-model properties over element-name conditions in data triggers"],"tags":["wpf","xaml","datatrigger","invalid-operation"],"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"}