Closed AJLeuer closed 3 years ago
@AJLeuer I suspect this is the issue resolved by this https://github.com/microsoft/microsoft-ui-xaml/pull/3136 PR. If that is the case the fix for this will be in the next Winui3 Preview. You could confirm that your scenario will be fixed by trying out your treeview usage with winui2 if you'd like.
Thanks Stephen. I guess I'll just have to wait for the next update then.
I'm writing WinUI 3 desktop application. The main window consists of a
TreeView
with the names of car makes as the parent items, and car models as the children.My problem: Here's the sequence of events that leads to the mystery exception:
DeleteCarMake()
is invoked via callback.DeleteCarMake()
deletes the selectedCarMake
and completely resets the contents of theCars
ObservableCollection
.TreeView
an exception is thrown.The problem seems to be connected to the complete removal of the contents of
Cars
and subsequent copying of data back intoCars
(note thatCars
serves as theItemsSource
for theTreeView
). If I simply remove thecarMakeToDelete
from Cars, the exception isn't thrown next time the user clicks theTreeView
. However, for reasons which my simplified code can't express, I need to be able to completelyClear()
Cars
' contents at every delete, not just remove a single item.What I'd like to know: How can I safely
Clear()
the contents of myCars
ObservableCollection
without causing an exception to be thrown the next time a user clicks on theTreeView
?One possible clue: If I don't define an event handler for the
TreeView
'sSelectionChanged
event in myMainWindow.xaml
then the exception never occurs. I'm not quite sure what this implies, but hopefully someone else can put together the pieces of the puzzle.Here's the relevant code (there's more than just this but I think these classes the ones that are germaine to the actual problem) :
MainWindow.xaml
:MainWindow.cs
: