Skip to content

Commit

Permalink
RemoveAtEnd on TreeViewNodeVector broken
Browse files Browse the repository at this point in the history
Ported an app from UWP to WinUI3 and noticed a bunch of UI 'corruption'
in our TreeView control when filtering elements. Tracked it down to
TreeView.RootNodes().RemoveAtEnd() always removing the first item
instead of the last item, which means you are left with a totally
unexpected result, as well as being unable to remove all the items due
to never being able to remove index 0.

The bug is due to incorrect parameter passing (ideally unused stack
variable warnings would be enabled and would catch this), where index
was intialized, but never passed to RemoveAt, causing the
`updateItemsSource` boolean to stand in for an index, causing us to
always delete index 0 or 1 instead of N-1.

The workaround is to just manually use RemoveAt instead of RemoveAtEnd.
  • Loading branch information
Galen Elias committed Dec 16, 2024
1 parent 650b2c1 commit 596236a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/controls/dev/TreeView/TreeViewNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ void TreeViewNodeVector::RemoveAt(unsigned int index, bool updateItemsSource,boo
void TreeViewNodeVector::RemoveAtEnd(bool updateItemsSource)
{
const auto index = GetVectorInnerImpl()->Size() - 1;
RemoveAt(updateItemsSource);
RemoveAt(index, updateItemsSource);
}

void TreeViewNodeVector::ReplaceAll(winrt::array_view<winrt::TreeViewNode const> values, bool updateItemsSource)
Expand Down

0 comments on commit 596236a

Please sign in to comment.