-
-
Notifications
You must be signed in to change notification settings - Fork 44
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Description:
Subject: Exception when closing page with selected cell in tv:TableView (WinUI.TableView)
Hello,
I encountered a reproducible crash in your tv:TableView control when a cell is selected and the host page/window is closed or unloaded. Short summary: the control continues input/hittest processing after the XAML visual tree is detached, which triggers WinRT/COM errors (RO_E_CLOSED) and a VisualTreeHelper error in DesktopWindowXamlSource mode.
Relevant native stack (summary)
- KernelBase.dll → combase.dll → Microsoft.UI.Input.dll → (control code) → call into VisualTreeHelper / FindElementsInHostCoordinates.
What I believe is happening
- The control performs pointer/hit-test operations (calls into
VisualTreeHelper::FindElementsInHostCoordinatesor similar) while the XAML visual tree is already being torn down or when no validUIElementroot is provided for DesktopWindowXamlSource. This causes invalid parameter errors (0x80070057) or access to already-closed WinRT objects (0x80000013). The root cause is a lifecycle race: input processing or asynchronous handlers outlive the visual tree.
Suggested fixes
- On control unload/dispose:
- Stop/ cancel all async work and timers.
- Unregister input/event handlers (PointerPressed/PointerMoved/Focus etc.).
- Release pointer captures (
ReleasePointerCapture/ReleasePointerCaptures) and clear selection. - Clear
ItemsSource,SelectedItem/SelectedCellsand avoid further access to detached UI elements.
- Before calling
FindElementsInHostCoordinates, ensure a validUIElementis passed when running under DesktopWindowXamlSource; guard against null / detached roots. - Add and expose a public cleanup API (e.g.,
Detach,Dispose,StopInputProcessing) so hosts can deterministically tear down the control. - Gracefully handle RO_E_CLOSED and related COM exceptions inside the control to avoid crashing the host.
- Consider adding defensive synchronization to avoid asynchronous continuations touching the control after Unloaded.
What I can provide on request
- Managed callstack (stack frames from the .NET side) at the moment of the exception.
- Minimal repro project and the exact XAML + page code.
- The specific NuGet package id and version used in my project (if you request it).
Please let me know which data you need and I will attach the managed stack and a small repro. Thank you.
Steps to Reproduce:
Reproduction steps (minimal)
- Open the page containing
tv:TableView. - Select any cell.
- Close the page / navigate away / close the app so the page is unloaded.
- Observe crash/exception (first-chance or fatal).
Expected behavior:
Observed exceptions
- RO_E_CLOSED (0x80000013): "The given object has already been closed / disposed and may no longer be used."
- 0x80070057 from
VisualTreeHelper::FindElementsInHostCoordinates:
"FindElementsInHostCoordinates failed because the XAML runtime is running to support DesktopWindowXamlSource, and in this mode a UIElement must be provided."
Screenshots:
Environment:
Environment
- WinUI 3 (Desktop) app hosted with DesktopWindowXamlSource
- .NET 10, Visual Studio 2022
tv:TableViewused in a Page (Pages/MainPage.xaml) withSelectionMode="Single"andSelectionUnit="Cell".- ItemsSource bound via
{x:Bind Documents}
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working