microsoft / microsoft/microsoft-ui-xaml
Calling ItemsView.StartBringItemIntoView() Freezes The WinUI3 App
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
Calling ItemsView.StartBringItemIntoView() Freezes The WinUI3 App
### Steps to reproduce the bug
On a VM2Control Behavior. I try to sync the selected Item with view model.
In the setter, after selecting, I try to scroll the view to the selected item by calling .StartBringItemIntoView().
I use a KeyboardAccelerator on button " )" to trigger the setter quickly.
It works fine at the beginning.
After dozens of calls, the app freezes.
When i pause the app in the VS debugger, the yellow bar is on the line of calling the StartBringItemIntoView().
It happens when the setter is called during the layout updating process of the itemsView is not completed.
Maybe there is something wrong.
`
public class SyncSelectionBehavior : Behavior {
public static readonly DependencyProperty SelectedIndexProperty =
DependencyProperty.Register(nameof(SelectedIndex), typeof(int), typeof(SyncSelectionBehavior), new PropertyMetadata(null));
public int SelectedIndex {
get => (int)GetValue(SelectedIndexProperty);
set {
SetValue(SelectedIndexProperty, value);
if (value >= 0) {
if (AssociatedObject.ItemsSource != null && AssociatedObject.ItemsSource is ICollection collection) {
if (value < collection.Count) {
AssociatedObject.DeselectAll();
AssociatedObject.Select(value);
if (value == collection.Count - 1) {
AssociatedObject.StartBringItemIntoView(value, new BringIntoViewOptions { AnimationDesired = false, VerticalAlignmentRatio = 1f });
} else {
AssociatedObject.StartBringItemIntoView(value, new BringIntoViewOptions { AnimationDesired = false });
}
}
}
else {
AssociatedObject.DeselectAll();
AssociatedObject.Select(value);
AssociatedObject.StartBringItemIntoView(value, new BringIntoViewOptions() { AnimationDesired = false });
}
}
}
}
}
`
### Expected behavior
The StartBringItemIntoView() method should act as it is designed.
### Screenshots
_No response_
### NuGet package version
WinUI 3 - Windows App SDK 1.6.0: 1.6.240829007
### Windows version
Windows 11 (22H2): Build 22621
### Additional context
_No response_
Contributor guide
Research direction
Reproduce the freeze using the provided SyncSelectionBehavior setter, ItemsView.StartBringItemIntoView(), and rapid prev/next KeyboardAccelerator actions on Windows 11 with Windows App SDK 1.6.240829007. Trace the behavior when the setter runs during ItemsView layout updates; done means repeated selection changes no longer freeze the WinUI 3 app.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100