dotnet/maui · error · XamlParseException
Unable to find a TragetType for the Bindable Property. Try p
Error message
Unable to find a TragetType for the Bindable Property. Try prefixing it with the TargetType.
What it means
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.
Source
Thrown at src/Controls/src/Core/BindablePropertyConverter.cs:158
return vsTarget.GetType();
if (parents[3] is not VisualStateGroupList)
throw new XamlParseException($"Expected {nameof(VisualStateGroupList)} but found {parents[3]}.", lineInfo);
if (parents[4] is VisualElement veTarget)
return veTarget.GetType();
if (parents[4] is not Setter)
throw new XamlParseException($"Expected {nameof(Setter)} but found {parents[4]}.", lineInfo);
if (parents[5] is TriggerBase trigger)
return trigger.TargetType;
// These must be part of a Style; verify that
if (parents[5] is Style style)
return style.TargetType;
throw new XamlParseException($"Unable to find a TragetType for the Bindable Property. Try prefixing it with the TargetType.", lineInfo);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value is not BindableProperty bp)
throw new NotSupportedException();
return $"{bp.DeclaringType.Name}.{bp.PropertyName}";
}
}
}
View on GitHub (pinned to f377ff1c5e)
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.
Example fix
<!-- before --> <Style><!-- missing TargetType --> ... <Setter Property="BackgroundColor" Value="Red" /> </Style> <!-- after --> <Style TargetType="VisualElement"> ... <Setter Property="VisualElement.BackgroundColor" Value="Red" /> </Style>
Defensive patterns
Strategy: validation
Validate before calling
// Qualify the property with its owner type so parent inference is unnecessary: // Property="VisualElement.BackgroundColor"
Try / catch
try { /* compile */ }
catch (XamlParseException ex) when (ex.Message.Contains("TragetType"))
{
// note: message has a typo; guide author to qualify property or set TargetType
} Prevention
- Always set TargetType on Styles that use visual states.
- Qualify Setter.Property with the owner type when in doubt.
When it happens
Trigger: 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.
Common situations: A Style with no TargetType attribute; visual states nested under a non-Style, non-Trigger element; refactoring that detached the Setter from its Style.
Related errors
- Expected {nameof(VisualStateGroup)} but found {parents[2]}.
- Expected {nameof(VisualStateGroupList)} but found {parents[3
- Expected {nameof(Setter)} but found {parents[4]}.
- Can't resolve {0}
- Can't resolve {parts[0]}
AI-assisted analysis of dotnet/maui@f377ff1c5e (2026-08-13).
Data as JSON: /api/errors/fc72d4b9a93f74ce.
Report an issue: GitHub.