Skip to content

fix: replace deprecated ListView with CollectionView in TodoApp.MAUI#566

Merged
adrianhall merged 1 commit into
CommunityToolkit:mainfrom
adrianhall:issues/515
Jul 11, 2026
Merged

fix: replace deprecated ListView with CollectionView in TodoApp.MAUI#566
adrianhall merged 1 commit into
CommunityToolkit:mainfrom
adrianhall:issues/515

Conversation

@adrianhall

Copy link
Copy Markdown
Collaborator

Summary

Replaces the deprecated Microsoft.Maui.Controls.ListView with CollectionView in the TodoApp.MAUI sample's MainPage, eliminating the CS0618 obsolete-API warning surfaced by the new Windows CI (#514):

MainPage.xaml.cs(34,23): warning CS0618: 'ListView' is obsolete: 'ListView is deprecated. Please use CollectionView instead.'

Changes

  • MainPage.xaml: replaced <ListView>/<ListView.ItemTemplate> with <CollectionView>/<CollectionView.ItemTemplate>, removing the <ViewCell> wrapper (not used by CollectionView item templates — the DataTemplate content is now the direct visual). Added SelectionMode="Single" and swapped ItemTapped="OnListItemTapped" for SelectionChanged="OnListItemTapped".
  • MainPage.xaml.cs: updated OnListItemTapped to accept SelectionChangedEventArgs, reading the tapped item via e.CurrentSelection.FirstOrDefault() instead of e.Item, and cast sender to CollectionView (instead of ListView) to reset SelectedItem = null after handling the tap — preserving the existing "tap to act, then deselect" behavior.
  • Resources/Styles/Styles.xaml: removed the now-unused implicit <Style TargetType="ListView"> (SeparatorColor/RefreshControlColor), since ListView is no longer used anywhere in this project and CollectionView doesn't have equivalent properties.

Testing

  • dotnet build/dotnet test against the main solution (unaffected, since these are sample-only changes not included in Datasync.Toolkit.sln).
  • Verified via the fork's Build Samples CI workflow (workflow_dispatch on issues/515): all sample jobs passed, including todoapp-maui (Android/iOS) and todoapp-windows (which builds the MAUI Windows TFM head — the job that originally surfaced this warning). Confirmed 0 Warning(s) in the MAUI Windows build step logs, versus the previous CS0618 warning.
  • Run: https://github.com/adrianhall/CommunityToolkit-Datasync/actions/runs/29148210258

Closes #515

Replaces the obsolete Microsoft.Maui.Controls.ListView (CS0618) with
CollectionView in the TodoApp.MAUI sample's MainPage, removing the
ViewCell wrapper the new control doesn't use and switching the tap
handler from ItemTapped/ItemTappedEventArgs to
SelectionChanged/SelectionChangedEventArgs (SelectionMode=Single,
resetting SelectedItem afterward to preserve tap-then-deselect
behavior). Also removes the now-unused implicit ListView style from
Styles.xaml.

Closes CommunityToolkit#515
@adrianhall adrianhall merged commit 7ea5028 into CommunityToolkit:main Jul 11, 2026
20 checks passed
@adrianhall adrianhall deleted the issues/515 branch July 11, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TodoApp.MAUI: Replace deprecated ListView with CollectionView (CS0618)

1 participant