{"record":{"id":"c1658199a1e0bbb4","repo":"dotnet/wpf","slug":"sr-format-sr-unexpectedvaluetypefordatatrigger-propertyvalue-c16581","errorCode":null,"errorMessage":"SR.Format(SR.UnexpectedValueTypeForDataTrigger, propertyValue.ValueType)","messagePattern":"SR\\.Format\\(SR\\.UnexpectedValueTypeForDataTrigger, propertyValue\\.ValueType\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MultiDataTrigger.cs","lineNumber":132,"sourceCode":"                    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;\n                    case PropertyValueType.PropertyTriggerResource:\n                        propertyValue.ValueType = PropertyValueType.DataTriggerResource;\n                        break;\n                    default:\n                        throw new InvalidOperationException(SR.Format(SR.UnexpectedValueTypeForDataTrigger, propertyValue.ValueType));\n                }\n\n                // Put back modified struct\n                PropertyValues[i] = propertyValue;\n            }\n\n            base.Seal();\n        }\n\n        // evaluate the current state of the trigger\n        internal override bool GetCurrentState(DependencyObject container, UncommonField<HybridDictionary[]> dataField)\n        {\n            bool retVal = (TriggerConditions.Length > 0);\n\n            for( int i = 0; retVal && i < TriggerConditions.Length; i++ )\n            {\n                retVal = TriggerConditions[i].ConvertAndMatch(StyleHelper.GetDataTriggerValue(dataField, container, TriggerConditions[i].Binding));\n            }","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/MultiDataTrigger.cs#L114-L150","documentation":"During MultiDataTrigger.Seal(), each PropertyValue in the trigger's PropertyValues list must have a ValueType of Trigger or PropertyTriggerResource so it can be remapped to the DataTrigger variants. Any other internal PropertyValueType indicates corrupted or improperly constructed setter state, so WPF throws InvalidOperationException including the unexpected value type.","triggerScenarios":"Programmatically constructing a MultiDataTrigger and injecting PropertyValues/Setter objects whose internal PropertyValueType is not Trigger or PropertyTriggerResource, then sealing the style; not reachable through normal XAML parsing of <MultiDataTrigger.Setters>.","commonSituations":"Custom framework code or styling helpers that build PropertyValue structs directly; cloning/reusing setter internals across trigger types; low-level manipulation of the sealed style machinery.","solutions":["Build setters via the public Setters collection (Setter objects) instead of manipulating PropertyValues directly","Do not reuse PropertyValues or Setter internals created for a different trigger type (Trigger/MultiTrigger) in a MultiDataTrigger","Recreate the MultiDataTrigger from scratch rather than mutating its internals after construction"],"exampleFix":"// before\nvar pv = new PropertyValue(PropertyValueType.PropertyTrigger, value);\ntrigger.PropertyValues.Add(pv); // wrong internal type\n// after\ntrigger.Setters.Add(new Setter(TextBlock.TextProperty, value));","handlingStrategy":"validation","validationCode":"// Only build triggers through the public API\nif (trigger.Setters.Count == 0 && trigger.PropertyValuesInternalCount > 0)\n    throw new InvalidOperationException(\"PropertyValues manipulated directly; use Setters\");","typeGuard":null,"tryCatchPattern":"try { style.Seal(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"value type\")) {\n    // rebuild the trigger via Setters collection\n}","preventionTips":["Construct setters only through MultiDataTrigger.Setters","Never reuse PropertyValue structs between Trigger and DataTrigger types","Treat trigger internals as sealed after style application"],"tags":["wpf","datatrigger","internal","invalid-operation"],"backgroundTag":"invalid-enum-value","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}