{"record":{"id":"fc72d4b9a93f74ce","repo":"dotnet/maui","slug":"unable-to-find-a-tragettype-for-the-bindable-prope","errorCode":null,"errorMessage":"Unable to find a TragetType for the Bindable Property. Try prefixing it with the TargetType.","messagePattern":"Unable to find a TragetType for the Bindable Property\\. Try prefixing it with the TargetType\\.","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Controls/src/Core/BindablePropertyConverter.cs","lineNumber":158,"sourceCode":"\t\t\t\treturn vsTarget.GetType();\n\n\t\t\tif (parents[3] is not VisualStateGroupList)\n\t\t\t\tthrow new XamlParseException($\"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.\", lineInfo);\n\n\t\t\tif (parents[4] is VisualElement veTarget)\n\t\t\t\treturn veTarget.GetType();\n\n\t\t\tif (parents[4] is not Setter)\n\t\t\t\tthrow new XamlParseException($\"Expected {nameof(Setter)} but found {parents[4]}.\", lineInfo);\n\n\t\t\tif (parents[5] is TriggerBase trigger)\n\t\t\t\treturn trigger.TargetType;\n\n\t\t\t// These must be part of a Style; verify that \n\t\t\tif (parents[5] is Style style)\n\t\t\t\treturn style.TargetType;\n\n\t\t\tthrow new XamlParseException($\"Unable to find a TragetType for the Bindable Property. Try prefixing it with the TargetType.\", lineInfo);\n\n\t\t}\n\n\t\tpublic override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)\n\t\t{\n\t\t\tif (value is not BindableProperty bp)\n\t\t\t\tthrow new NotSupportedException();\n\t\t\treturn $\"{bp.DeclaringType.Name}.{bp.PropertyName}\";\n\t\t}\n\t}\n}\n","sourceCodeStart":140,"sourceCodeEnd":170,"githubUrl":"https://github.com/dotnet/maui/blob/f377ff1c5ee04d334d8a925f50c83a6b7afddf03/src/Controls/src/Core/BindablePropertyConverter.cs#L140-L170","documentation":"Catch-all XamlParseException raised at the end of FindTypeForVisualState when no ancestor in the visual-state parent chain exposed a TargetType (neither a TriggerBase nor a Style). The converter exhausted parents[5] for a Trigger or Style and found neither, so it cannot infer which type the BindableProperty belongs to. Note the message contains a typo ('TragetType') which is preserved in source.","triggerScenarios":"A visual-state Setter whose Style/Trigger parent chain is incomplete or whose Style lacks a TargetType; using visual states inside a custom container that is neither Style nor TriggerBase and provides no TargetType.","commonSituations":"A Style with no TargetType attribute; visual states nested under a non-Style, non-Trigger element; refactoring that detached the Setter from its Style.","solutions":["Prefix the property with its owner type, e.g. Property=\"VisualElement.BackgroundColor\", so the converter does not need parent inference.","Ensure the enclosing Style has a TargetType set.","Move the visual-state Setter back under a proper Style or Trigger."],"exampleFix":"<!-- before -->\n<Style><!-- missing TargetType -->\n  ...\n  <Setter Property=\"BackgroundColor\" Value=\"Red\" />\n</Style>\n\n<!-- after -->\n<Style TargetType=\"VisualElement\">\n  ...\n  <Setter Property=\"VisualElement.BackgroundColor\" Value=\"Red\" />\n</Style>","handlingStrategy":"validation","validationCode":"// Qualify the property with its owner type so parent inference is unnecessary:\n// Property=\"VisualElement.BackgroundColor\"","typeGuard":null,"tryCatchPattern":"try { /* compile */ }\ncatch (XamlParseException ex) when (ex.Message.Contains(\"TragetType\"))\n{\n    // note: message has a typo; guide author to qualify property or set TargetType\n}","preventionTips":["Always set TargetType on Styles that use visual states.","Qualify Setter.Property with the owner type when in doubt."],"tags":["maui","xaml","visualstate","converter","style","targettype"],"backgroundTag":null,"analyzedSha":"f377ff1c5ee04d334d8a925f50c83a6b7afddf03","analyzedAt":"2026-08-13T14:26:18.069Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}