Skip to content
Shiny.NET

State & Implicit Transitions

Attach VisualTransitions to an element and its visual state changes animate instead of snapping. This covers VisualStateManager.GoToState, state triggers, and MAUI’s own Pressed, PointerOver, Focused and Disabled states. The VisualStateGroups themselves don’t change.

<Button Text="Press me">
<kf:StateTransitions.Transitions>
<kf:VisualTransition Duration="0:0:0.2" />
<kf:VisualTransition To="Pressed" Duration="0:0:0.08" Easing="CubicOut" />
<kf:VisualTransition From="Pressed" Duration="0:0:0.45" Easing="spring(0.35, 14)" />
</kf:StateTransitions.Transitions>
<VisualStateManager.VisualStateGroups>
<VisualStateGroupList>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="#2563EB" />
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Pressed">
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="#7C3AED" />
<Setter Property="Scale" Value="0.94" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</VisualStateManager.VisualStateGroups>
</Button>
Property Default Notes
Group any The visual state group it applies to.
From / To any The state being left and entered. Unset or * matches any state.
Duration 0:0:0.15
Delay 0 The old value holds during the delay.
Easing CubicOut Any curve text, springs included.
ReducedMotion Auto Under the OS reduced-motion setting, Auto snaps.
Animation — An extra Keyframes or Choreography played on the change, such as a shake on entering Error.

The most specific match wins: naming the Group scores highest, then naming From and/or To. A state change that no transition matches snaps, as it does without any transitions.

  • Interrupting a transition mid-flight starts the next one from the value on screen.
  • Setters with TargetName animate their named element.
  • StateTransitions.GoToState(view, "Pressed", useTransitions: false) snaps one change even when transitions are attached.

An animation that runs for as long as the element is in a state, such as a pulse while busy. It stops and releases every property when the element leaves the state.

<kf:StateTransitions.Transitions>
<kf:VisualTransition Duration="0:0:0.3" />
<kf:VisualTransition To="Error" Animation="{StaticResource Shake}" />
<kf:StateAnimation State="Busy" Animation="{StaticResource Pulse}" />
</kf:StateTransitions.Transitions>

VisualStateGroup is sealed and raises nothing public when its state changes. So the library adds one setter to the end of each state’s list, which writes a marker property. When the marker changes, every setter of the new state has just been applied. Each property that changed in that pass then animates from the value it was showing to the value the state set. The animation runs through the animation layer, so the state still owns the value and the transition lands on it.

PropertyTransition is the CSS transition property for MAUI: any change to a listed property animates, whether it comes from a binding, a style, a trigger or code.

<BoxView Opacity="{Binding Fade}" Scale="{Binding Zoom}" Rotation="{Binding Spin}">
<kf:PropertyTransitions.Transitions>
<kf:PropertyTransition Property="Opacity" Duration="0:0:0.25" />
<kf:PropertyTransition Property="Scale" Duration="0:0:0.6" Easing="spring(0.4, 13)" />
<kf:PropertyTransition Property="Rotation" Duration="0:0:0.5" Easing="EaseInOut" />
<kf:PropertyTransition BindableProperty="{x:Static Label.TextColorProperty}" />
</kf:PropertyTransitions.Transitions>
</BoxView>
Property Default Notes
Property — A registered name (Opacity, Scale, BackgroundColor, …), or All for every registered property the element has.
BindableProperty — Any bindable property, for properties that aren’t registered.
Duration 0:0:0.2
Delay 0
Easing CubicOut
ReducedMotion Auto

The value that was set stays in the property’s own source the whole time (AnimationLayer.GetBaseValue returns it). Only the value on screen travels toward it, and while it does, the property getter returns the on-screen value. Values set before the element has a handler (its initial values) don’t animate. Rotation takes the shortest arc, and colours blend in Oklab, the same as in keyframes.

A transition to or from “no value” fades instead of snapping. For example, a background colour that a state sets and the normal state leaves unset fades through the colour’s transparent version.