{"record":{"id":"5bfba4a966d76dc9","repo":"HandyOrg/HandyControl","slug":"exceptionstringtable-defaulttriggerattribute","errorCode":null,"errorMessage":"ExceptionStringTable.DefaultTriggerAttributeInvalidTriggerTypeSpecifiedExceptionMessage","messagePattern":"ExceptionStringTable\\.DefaultTriggerAttributeInvalidTriggerTypeSpecifiedExceptionMessage","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Shared/System.Windows.Interactivity/DefaultTriggerAttribute.cs","lineNumber":20,"sourceCode":"using System.Collections;\nusing System.Globalization;\n\nnamespace HandyControl.Interactivity;\n\n[AttributeUsage(AttributeTargets.Property | AttributeTargets.Class, AllowMultiple = true)]\npublic sealed class DefaultTriggerAttribute : Attribute\n{\n    private readonly object[] _parameters;\n\n    public DefaultTriggerAttribute(Type targetType, Type triggerType, object parameter) : this(targetType,\n        triggerType, new[] { parameter })\n    {\n    }\n\n    public DefaultTriggerAttribute(Type targetType, Type triggerType, params object[] parameters)\n    {\n        if (!typeof(TriggerBase).IsAssignableFrom(triggerType))\n            throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,\n                ExceptionStringTable.DefaultTriggerAttributeInvalidTriggerTypeSpecifiedExceptionMessage,\n                new object[] { triggerType.Name }));\n        TargetType = targetType;\n        TriggerType = triggerType;\n        _parameters = parameters;\n    }\n\n    public IEnumerable Parameters =>\n        _parameters;\n\n    public Type TargetType { get; }\n\n    public Type TriggerType { get; }\n\n    public TriggerBase Instantiate()\n    {\n        object obj2 = null;\n        try","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/HandyOrg/HandyControl/blob/2c0875ebd67326e0c67282967e3e809c69282fee/src/Shared/System.Windows.Interactivity/DefaultTriggerAttribute.cs#L2-L38","documentation":"The DefaultTriggerAttribute constructor requires its triggerType parameter to be a type deriving from TriggerBase. Passing any other Type throws ArgumentException DefaultTriggerAttributeInvalidTriggerTypeSpecifiedExceptionMessage with the offending type name.","triggerScenarios":"Writing [DefaultTrigger(typeof(Button), typeof(SomeNonTriggerType), ...)] or calling new DefaultTriggerAttribute(targetType, triggerType, params) with a triggerType where typeof(TriggerBase).IsAssignableFrom(triggerType) is false.","commonSituations":"Typo or autocomplete picking an EventTrigger from the wrong namespace; passing the target class itself as the trigger type; copy-pasting an attribute line and forgetting to change the trigger type; using TriggerAction-derived types by mistake.","solutions":["Pass a Type that derives from TriggerBase (e.g. typeof(EventTrigger), typeof(PropertyChangedTrigger)).","Verify the trigger type's namespace — Microsoft.Xaml.Behaviors TriggerBase, not a same-named custom class.","Ensure custom triggers inherit from TriggerBase before referencing them in DefaultTriggerAttribute.","Fix the constructor call if invoking DefaultTriggerAttribute directly via reflection or codegen."],"exampleFix":"// before\n[DefaultTrigger(typeof(Button), typeof(Button), \"Click\")]\n// after\n[DefaultTrigger(typeof(Button), typeof(EventTrigger), \"Click\")]","handlingStrategy":"validation","validationCode":"if (triggerType == null || !typeof(TriggerBase).IsAssignableFrom(triggerType))\n    throw new ArgumentException($\"{triggerType?.Name} must derive from TriggerBase\");","typeGuard":"static bool IsValidTriggerType(Type t) => t != null && typeof(TriggerBase).IsAssignableFrom(t);","tryCatchPattern":"try { var attr = new DefaultTriggerAttribute(targetType, triggerType); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"InvalidTriggerType\")) { /* fix trigger type */ }","preventionTips":["Only pass TriggerBase-derived types to DefaultTriggerAttribute.","Compile-time: reference the exact trigger class in the attribute.","Watch for same-named classes in different namespaces.","Ensure custom triggers inherit TriggerBase."],"tags":["wpf","interactivity","attribute","invalid-argument-value","trigger"],"backgroundTag":"invalid-argument-value","analyzedSha":"2c0875ebd67326e0c67282967e3e809c69282fee","analyzedAt":"2026-09-14T14:45:29.754Z","contentChangedAt":"2026-09-14T14:45:29.754Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}