Repository navigation
Description
GitHub Issue: n/a
Current behavior
VisualStateGroup.CurrentState is updated at the very start of VisualStateManager.GoToState, before a VisualTransition has run. On WinUI the new state only becomes CurrentState once the transition finishes.
Two visible consequences, both with a ProgressBar (its Updating -> Determinate change uses a non-zero VisualTransition):
- While the control is
Collapsed(so the transition storyboard never completes on WinUI),IsIndeterminate = falseleaves WinUI onIndeterminate; Uno reportsDeterminate. - While visible, reading
CurrentStatesynchronously right afterIsIndeterminate = falsegivesUpdatingon WinUI,Determinateon Uno.
Expected behavior
Same as WinUI: CurrentState and CurrentStateChanged follow the transition completion. WinUI source (dxaml/xcp/components/vsm):
VisualStateManagerActuator::ChangeVisualStatecallsBeginTransitionToState(only raisesCurrentStateChanging), and callsCompleteTransitionToStateright away only for a zero-duration transition.- For a non-zero transition,
CompleteTransitionToStateruns fromFinishVisualTransitionon storyboard completion. StandardVisualStateManagerDataSource::OnCompleteTransitionToStateis the only place that callsCVisualStateGroup::SetCurrentVisualStateand raisesCurrentStateChanged.
Uno: VisualStateGroup.GoToState assigns _current = targetValues; before starting the transition animation (src/Uno.UI/UI/Xaml/VisualStateGroup.cs, GoToState).
How to reproduce it
Runtime test (Uno.UI.RuntimeTests, Skia desktop):
var sut = new ProgressBar { Width = 200, IsIndeterminate = true };
TestServices.WindowHelper.WindowContent = sut;
await TestServices.WindowHelper.WaitForLoaded(sut);
await TestServices.WindowHelper.WaitForIdle();
VisualStateGroup GetGroup() => VisualStateManager.GetVisualStateGroups((FrameworkElement)VisualTreeHelper.GetChild(sut, 0)).Single(g => g.Name == "CommonStates");
sut.Visibility = Visibility.Collapsed;
await TestServices.WindowHelper.WaitForIdle();
sut.IsIndeterminate = false;
await TestServices.WindowHelper.WaitForIdle();
var collapsed = GetGroup().CurrentState?.Name; // WinUI: "Indeterminate", Uno: "Determinate"
sut.Visibility = Visibility.Visible;
sut.IsIndeterminate = true;
await TestServices.WindowHelper.WaitForIdle();
sut.IsIndeterminate = false;
var right = GetGroup().CurrentState?.Name; // WinUI: "Updating", Uno: "Determinate"Uno result (Skia desktop): Expected "Indeterminate" but was "Determinate" for the collapsed read.
Workaround
Don't rely on reading CurrentState synchronously after a state change; wait for CurrentStateChanged.
Works on UWP/WinUI
Yes, the WinUI values above come from a native WinUI runtime probe (same test, WinAppSDK head) and from the WinUI source listed above.
Environment
Uno.UI master 6aaf32516ac, net11.0-desktop (Skia). The Uno side was reproduced at runtime on Skia desktop only; the code path is not platform specific.
NuGet package version
master @ 6aaf325
Affected platforms
Skia (all heads share the code)
IDE
n/a
Relevant plugins
n/a
Anything else we need to know?
Mostly a test-portability issue: tests that read CurrentState right after a change must be excluded on native WinUI today. Fixing it means deferring _current (and CurrentStateChanged) to transition completion, which interacts with interrupted transitions and needs care.
Activity