-
Notifications
You must be signed in to change notification settings - Fork 674
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ListView reorder items doesn't trigger VectorChanged with winrt #8748
Comments
It's because you registered the event with struct MainPage : MainPageT<MainPage>
{
MainPage()
: m_layers{ winrt::single_threaded_observable_vector<winrt::hstring>() }
{
...
m_revoker = m_layers.VectorChanged(winrt::auto_revoke, { this, &MainPage::OnLayersVectorChanged });
}
...
private:
winrt::Windows::Foundation::Collections::IObservableVector<winrt::hstring>::VectorChanged_revoker m_revoker;
...
}; |
@HO-COOH, I believe this is a typo in the bug description. Looking at the provided sample application you'll found out that the revoker is saved into a class member as you suggested: |
@acouvert I don't see that line in the zip |
My bad, I realized that I was looking at an old archive from when the bug had been submitted. I may have looked at the bug in the past and came to same conclusion that you but somehow, I forgot to share it back here 😅. |
Describe the bug
If you try to bind a
ListView.ItemsSource
to anIObservableVector
, reordering the items from the UI with drag and drop won't update the data source behind. However, this works as expected if you do so in C# with anObservableCollection
.Because of that, as soon as you reorder the list view in the UI, there is a inconsistency between what is shown and the actual collection. It should be easy to allow the user to reorder item, but because of this bug, it is not at all.
Steps to reproduce the bug
To repro the issue, you can test those 2 sample projects. The first one is in winrt with an ObservableVector, and the second one is in C# with a ObservableCollection. Both contain the same ListView:
And the same setup for the collection:
ReorderListViewSample.zip
ListViewReoderCSharp.zip
But if you but a breakpoint in the CollectionChanged method, you will see that it is called in the C# project, but not in the C++ winrt one.
Expected behavior
Reordering a ListView from a winrt project should, as with an ObservableCollection, trigger the VectorChanged event, and actually update the source collection (bound to ItemsSource).
Screenshots
No response
NuGet package version
None
Windows version
Windows 11 (22H2): Build 22621
Additional context
No response
The text was updated successfully, but these errors were encountered: