AvaloniaUI/Avalonia · error · InvalidOperationException
Cannot animate direct property {property} on {display}.
Error message
Cannot animate direct property {property} on {display}. What it means
Thrown by Transitions.Validate when a transition added to a Transitions collection targets a direct (non-styled) AvaloniaProperty. Avalonia's animation system can only bind styled properties, so animating a direct property is unsupported and rejected at insertion time.
Source
Thrown at src/Avalonia.Base/Animation/Transitions.cs:29
{
/// <summary>
/// Initializes a new instance of the <see cref="Transitions"/> class.
/// </summary>
public Transitions()
{
ResetBehavior = ResetBehavior.Remove;
Validator = this;
}
void IAvaloniaListItemValidator<ITransition>.Validate(ITransition item)
{
Dispatcher.UIThread.VerifyAccess();
var property = item.Property;
if (property.IsDirect)
{
var display = item is TransitionBase transition ? transition.DebugDisplay : item.ToString();
throw new InvalidOperationException($"Cannot animate direct property {property} on {display}.");
}
}
}
}
View on GitHub (pinned to 11c5427268)
Solutions
- Target only styled properties (registered via AvaloniaProperty.Register) in transitions.
- If you own the property, re-register it as styled, or wrap it so animation goes through a styled property.
- Remove the offending transition from the collection.
Example fix
// before
control.Transitions = new Transitions
{
new DoubleTransition { Property = MyControl.SomeDirectProperty, Duration = TimeSpan.FromSeconds(0.2) }
};
// after
control.Transitions = new Transitions
{
new DoubleTransition { Property = Visual.OpacityProperty, Duration = TimeSpan.FromSeconds(0.2) }
}; Defensive patterns
Strategy: validation
Validate before calling
if (transition.Property.IsDirect)
throw new InvalidOperationException($"Cannot animate direct property {transition.Property}"); Type guard
static bool IsAnimatable(AvaloniaProperty p) => !p.IsDirect;
Try / catch
try { control.Transitions = new Transitions { transition }; }
catch (InvalidOperationException ex) when (ex.Message.Contains("direct property"))
{ /* pick a styled property or drop the transition */ } Prevention
- Only target styled properties with transitions.
- When authoring controls, expose animatable properties as styled.
When it happens
Trigger: Adding a transition whose Property is a DirectProperty (e.g. a class registered via RegisterDirect) to a control's Transitions list; binding a transition to a property declared as direct.
Common situations: Mistakenly pointing a DoubleTransition at a direct property like a POCO-style getter/setter property; upgrading a control whose property was changed from styled to direct.
Related errors
- Transition has no property specified.
- Transition has no property specified.
- Transition elements have different parents.
- Cannot determine visual parent.
- Animation has no key frames
AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13).
Data as JSON: /api/errors/d07919b6b5df0672.
Report an issue: GitHub.