You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First off, thanks for the PhotoGallery part of the app. I learned lots from it.
Background:
Something that did not click until I came across it on a blog: http://lpains.net/articles/2020/xamarin-forms-collection-view-selected-items/
was that when the docs say to use this: public ObservableCollection<object> SelectedPhotos
they actually mean object not what ever object you are using in the CollectionView. As long as I was using myObject things were failing a bit. It was almost working, but not quite. When I changed myObject to object. Things started looking up.
Issue:
Now, that I was using object in the SelectedPhotos, things like the LongPress would select the photo that was receiving the LongPress. However, any Photo that I tapped after that got ignored.
Well, what actually happened is that in this code in PhotoGalleryViewModel:
when I was doing the second and subsequent tap of a multi-select, the program would enter OnPressed and enter the first if block since SelectionMode was Multiple. Then it wrote out the Debug stuff. Then it checked if the obj was already in _selectedPhotos. Lo and hehold, for every tap but the first LongPress, obj was contained in _selectedPhotos - and so it got removed. (this code I expect was intended to remove an entry from the list upon the Photo being tapped a second time)
After comparing your code and my code and many other things, I found the cause of the issue. My NuGets were newer than yours. I'll list what I am using:
Xamarin Community Toolkit 1.3.0-pre2
Xamarin.Essentials 1.7.0
Xamarin.Forms 5.0.0.2083
Visual Studio 2019 current
Win 10
When I updated this app to the same versions, it behaved the same way.
It looks like something in what got updated now takes care of the adding to the SelectedPhotos as well as removing ones that get taped a second time. When I remove this code:
if (_selectedPhotos.Contains(obj))
SelectedPhotos.Remove(obj);
else
SelectedPhotos.Add(obj);
it all seems to work - at least for what I tested.
The text was updated successfully, but these errors were encountered:
First off, thanks for the PhotoGallery part of the app. I learned lots from it.
Background:
Something that did not click until I came across it on a blog:
http://lpains.net/articles/2020/xamarin-forms-collection-view-selected-items/
was that when the docs say to use this:
public ObservableCollection<object> SelectedPhotos
they actually mean object not what ever object you are using in the CollectionView. As long as I was using myObject things were failing a bit. It was almost working, but not quite. When I changed myObject to object. Things started looking up.
Issue:
Now, that I was using object in the SelectedPhotos, things like the LongPress would select the photo that was receiving the LongPress. However, any Photo that I tapped after that got ignored.
Well, what actually happened is that in this code in PhotoGalleryViewModel:
when I was doing the second and subsequent tap of a multi-select, the program would enter OnPressed and enter the first if block since SelectionMode was Multiple. Then it wrote out the Debug stuff. Then it checked if the obj was already in _selectedPhotos. Lo and hehold, for every tap but the first LongPress, obj was contained in _selectedPhotos - and so it got removed. (this code I expect was intended to remove an entry from the list upon the Photo being tapped a second time)
After comparing your code and my code and many other things, I found the cause of the issue. My NuGets were newer than yours. I'll list what I am using:
Xamarin Community Toolkit 1.3.0-pre2
Xamarin.Essentials 1.7.0
Xamarin.Forms 5.0.0.2083
Visual Studio 2019 current
Win 10
When I updated this app to the same versions, it behaved the same way.
It looks like something in what got updated now takes care of the adding to the SelectedPhotos as well as removing ones that get taped a second time. When I remove this code:
it all seems to work - at least for what I tested.
The text was updated successfully, but these errors were encountered: