maui
maui copied to clipboard
ListView duplicate first item
Description
If a ListView is initially hidden, then made visible, the first item added appears twice, even though the ItemSource contains only one item. Adding more items causes the second item to display the 2 values overlapping.
Steps to Reproduce
Per repo, click Show radio button to show the ListView and add the first value (which shows twice). Click the button to add more rows -- the second entry ("2") shows on the second row as it should, but the first value is still there overlapping it.
Link to public reproduction project repository
https://github.com/mike3sullivan/MauiViewListDuplicateItem
Version with bug
6.0.486 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows 10
Did you find any workaround?
No response
Relevant log output
if it helps, attempting to Clear the ItemSource parameter causes a crash with the stack trace of:
This collection cannot work with indices larger than Int32.MaxValue - 1 (0x7FFFFFFF - 1). (Parameter 'index')
at ABI.System.Collections.IList.ToAbiHelper.EnsureIndexInt32(UInt32 index, Int32 listCapacity)
at ABI.System.Collections.IList.ToAbiHelper.GetAt(UInt32 index)
at ABI.System.Collections.IList.Vftbl.Do_Abi_GetAt_0(IntPtr thisPtr, UInt32 index, IntPtr* result)
--- End of stack trace from previous location ---
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|20_0(Int32 hr)
at ABI.Microsoft.UI.Xaml.IUIElementMethods.UpdateLayout(IObjectReference _obj)
at Microsoft.Maui.Controls.Internals.TemplatedItemsList2.OnProxyCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) at Microsoft.Maui.Controls.ListProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) at Microsoft.Maui.Controls.ListProxy.WeakNotifyProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection
1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection1.ClearItems() at System.Collections.ObjectModel.Collection
1.Clear()
Sorry but this seems you didn't upload the sample to the repository, can you check that please.
Thanks

Hi @mike3sullivan. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
Sorry - guess I didn't commit the upload. Done.
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.
Verified this issue with Visual Studio 17.7.0 Preview 1.0. Can repro on windows platform with sample project. MauiViewListDuplicateItem
We are also seeing a situation similar to this when removing the last item from an ObservableCollection that is bound to a ListView, a similar exception happens and then the ListView is left with an 'orphaned' child ViewCell that sits above the list and cannot be cleared, even when re-binding the ListView.
at ABI.System.Collections.IList.ToAbiHelper.EnsureIndexInt32(UInt32 index, Int32 listCapacity)
at ABI.System.Collections.IList.ToAbiHelper.GetAt(UInt32 index)
at ABI.System.Collections.IList.Vftbl.Do_Abi_GetAt_0(IntPtr thisPtr, UInt32 index, IntPtr* result)
--- End of stack trace from previous location ---
at WinRT.ExceptionHelpers.<ThrowExceptionForHR>g__Throw|39_0(Int32 hr)
at ABI.Microsoft.UI.Xaml.IUIElementMethods.UpdateLayout(IObjectReference _obj)
at Microsoft.UI.Xaml.UIElement.UpdateLayout()
at Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer.<OnCollectionChanged>b__23_0()
at Microsoft.Maui.Controls.DispatcherExtensions.DispatchIfRequired(IDispatcher dispatcher, Action action)
at Microsoft.Maui.Controls.Handlers.Compatibility.ListViewRenderer.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at Microsoft.Maui.Controls.Internals.TemplatedItemsList2.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at Microsoft.Maui.Controls.Internals.TemplatedItemsList
2.OnProxyCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at Microsoft.Maui.Controls.ListProxy.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at Microsoft.Maui.Controls.ListProxy.<>c__DisplayClass36_0.<OnCollectionChanged>b__0()
at Microsoft.Maui.Controls.DispatcherExtensions.DispatchIfRequired(IDispatcher dispatcher, Action action)
at Microsoft.Maui.Controls.ListProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at Microsoft.Maui.Controls.WeakNotifyCollectionChangedProxy.OnCollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.Collection
1.Remove(T item)
Same issue: https://github.com/microsoft/microsoft-ui-xaml/issues/8684
Hi @mike3sullivan. We have added the "s/try-latest-version" label to this issue, which indicates that we'd like you to try and reproduce this issue on the latest available public version. This can happen because we think that this issue was fixed in a version that has just been released, or the information provided by you indicates that you might be working with an older version.
You can install the latest version by installing the latest Visual Studio (Preview) with the .NET MAUI workload installed. If the issue still persists, please let us know with any additional details and ideally a reproduction project provided through a GitHub repository.
This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.
I've been experiencing this too. I created an updated version of mike3sullivan's demo: https://github.com/Felicity-R/ListViewBugDemo
It still reproduces:
I don't have the power to re-open this. @mike3sullivan can you re-open it?
Sorry -- I gave up on Maui desktop after all the problems I had getting consistency between Windows and MacOS [moved to Blazor hybrid]. I briefly tried to recreate the simple app in a brand new .Net 8 project and it didn't work right away. If this is a problem for you, i suggest you open a new bug report.