This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 44886 - UWP Listview ItemSelected event triggered twice for each selection
Summary: UWP Listview ItemSelected event triggered twice for each selection
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Windows (show other bugs)
Version: 2.3.2
Hardware: PC Windows
: Highest critical
Target Milestone: ---
Assignee: Samantha Houts
URL:
: 45219 47602 58898 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-09-29 14:11 UTC by Taylor
Modified: 2017-08-19 00:17 UTC (History)
15 users (show)

See Also:
Tags: ac, UWP, ListView fr
Is this bug a regression?: Yes
Last known good build: 2.3.4.247


Attachments
Reproduction Project (246.70 KB, application/x-zip-compressed)
2016-09-29 14:16 UTC, Taylor
Details

Description Taylor 2016-09-29 14:11:43 UTC
The ItemSelected event is being triggered twice each time an item is selected on a listview.  This issue is only occuring on UWP with the latest version of Forms(2.3.2.127).

I have attached an example reproduction case.  When the app launched you will be presented with a very basic listview with 5 items.  Selecting one of those items will cause a dialog to appear telling you which item you selected.  Additionally, when run in debug mode the item you selected will be printed to the console.

When running on Android or iOS this dialog is only displayed once, and the selected item is printed to the console once.  On UWP this happens twice.
Comment 1 Taylor 2016-09-29 14:16:28 UTC
Created attachment 17803 [details]
Reproduction Project
Comment 2 Samantha Houts 2016-09-30 23:03:32 UTC
Should be fixed in 2.3.4-pre1. Thank you!
Comment 3 Samantha Houts 2016-10-14 18:52:36 UTC
*** Bug 45219 has been marked as a duplicate of this bug. ***
Comment 4 Parmendra Kumar 2016-11-03 12:05:55 UTC
I have checked this issue and observed that this issue has been fixed with Xamarin.Forms 2.3.3-pre3.

Hence closing this issue.
Comment 5 Christer van der Meeren 2017-04-21 10:50:05 UTC
It seems this has resurfaced in 2.3.5-pre1. Not the first time an item is selected, but from the 2nd time, it's triggered twice.
Comment 6 Matthias H 2017-04-26 15:19:28 UTC
I can confirm that this is still an issue in 2.3.5-pre1. When using the ItemSelected event to display a new page, the back button has to be pressed twice because the event is triggered twice. The status of this bug should be changed, since it has not been fixed.
Comment 7 Dániel Buga 2017-04-27 07:24:35 UTC
This is still present, the property is set from here:

Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.ListViewRenderer.OnControlSelectionChanged(object sender, Windows.UI.Xaml.Controls.SelectionChangedEventArgs e)

and after that is is also set by Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.ListViewRenderer.ListOnTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs args)
Comment 8 Adam Patridge 2017-06-16 15:12:56 UTC
I spun up a new Forms project and copied in the App.cs from the attached repro ZIP. I then upgraded to the latest stable and threw a breakpoint in the ListView_ItemSelected method.

I do not see this issue in Xamarin.Forms v2.3.4.247 (combined with the UWP NuGet of v5.3.3, if that matters).

Unfortunately, When I then updated to the latest pre-release, v2.3.5.239-pre3, the breakpoint is hit twice.
Comment 9 Samantha Houts 2017-06-19 18:56:52 UTC
*** Bug 47602 has been marked as a duplicate of this bug. ***
Comment 10 Samantha Houts 2017-06-21 19:58:09 UTC
https://github.com/xamarin/Xamarin.Forms/pull/1005
Comment 11 Ray Kelly 2017-07-11 12:28:27 UTC
I just ran into this issue because of a crash reported by my users.  Getting the double event on ListView ItemSelected.  This is seriously still open??  Thank you Samantha, hopefully someone pulls your pull request soon!
Comment 12 Shawn Castrianni 2017-08-03 20:54:31 UTC
I think I am running into this bug in a slightly different way.  I tested on latest production XF, 2.3.4.247.  I have a custom ViewCell with a button in it.  I have a command attached to the Button and I have a command attached to the ListView.ItemTapped event.  When I touch the button within the ViewCell, BOTH commands get triggered, the command specific to the Button AND the ListView.ItemTapped.  Obviously, the ListView.ItemTapped should NOT be triggered.

Maybe this bug is the cause for the ListView.ItemTapped being triggered??
Comment 13 Ray Kelly 2017-08-05 13:54:59 UTC
I have a little more info on this.  Here is the call stack for the first ItemSelected event after I click on a viewcell.

>	MineChatForms.dll!MineChatForms.ServersPage.listView_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e) Line 472	C#
 	Xamarin.Forms.Core.dll!Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty property, object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject.SetValuePrivateFlags privateAttributes)	Unknown
 	Xamarin.Forms.Core.dll!Xamarin.Forms.Element.Xamarin.Forms.IElementController.SetValueFromRenderer(Xamarin.Forms.BindableProperty property, object value)	Unknown
 	Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.ListViewRenderer.SelectElementItem()	Unknown

Then the event fires again Immediatly, here is the call stack

>	MineChatForms.dll!MineChatForms.ServersPage.listView_ItemSelected(object sender, Xamarin.Forms.SelectedItemChangedEventArgs e) Line 472	C#
 	Xamarin.Forms.Core.dll!Xamarin.Forms.BindableObject.SetValueCore(Xamarin.Forms.BindableProperty property, object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject.SetValuePrivateFlags privateAttributes)	Unknown
 	Xamarin.Forms.Core.dll!Xamarin.Forms.ListView.NotifyRowTapped(int groupIndex, int inGroupIndex, Xamarin.Forms.Cell cell)	Unknown
 	Xamarin.Forms.Core.dll!Xamarin.Forms.ListView.NotifyRowTapped(int index, Xamarin.Forms.Cell cell)	Unknown
 	Xamarin.Forms.Platform.UAP.dll!Xamarin.Forms.Platform.UWP.ListViewRenderer.ListOnTapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs args)	Unknown


You can see an event for "NotifyRowTapped" in the group.  I do using grouping in my ListView.  Perhaps its firing the second event for the group?
Comment 14 Rui Marinho 2017-08-17 16:04:41 UTC
Should be fixed on 2.4.1-pre1
Comment 15 Jon Goldberger 2017-08-19 00:17:34 UTC
*** Bug 58898 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.