Skip to content
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

Collection View not populating with Observable Collection in Android #25633

Open
ISSPRO-Eng opened this issue Oct 31, 2024 · 4 comments
Open
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 s/needs-info Issue needs more info from the author t/bug Something isn't working
Milestone

Comments

@ISSPRO-Eng
Copy link

ISSPRO-Eng commented Oct 31, 2024

Description

I have a collection view that is bonded to an observable collection that populates with nearby BT devices.

Steps to Reproduce

This is a larger app, so I have not recreated the issue elsewhere. I will gladly share the GitHub repo if needed. This is a mini snippet of the code.

VIEW

     if (!ignore)
     {
             try
             {
                         _vm.AvailableDevices.Add(deviceObj);
                         Console.WriteLine(device.Name);
             }
            catch (Exception ex)
            {
                         Console.WriteLine(ex);
            }
     }

VIEW MODEL

        IDevice _device;
        
        public IDevice DeviceInterface { get => _device; }
        public string Name { get => _device.Name; }


          public Device(IDevice device)
        {
            _device = device;
        }
    }
    public class BTDeviceListPopupViewModel : BaseViewModel
    {
        private ObservableCollection<Device> _availableDevices = new ObservableCollection<Device>();
        private bool _isScanning;
        public ObservableCollection<Device> AvailableDevices { get => _availableDevices; 
                                                               set { _availableDevices = value; 
                                                                    OnPropertyChanged(nameof(AvailableDevices)); }  }`

Link to public reproduction project repository

https://github.com/ISSPRO-Eng/MauiProductionProgrammer (Currently Private)(Can make public if needed).

Version with bug

8.0.82 SR8.2

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

All Android Devices

Did you find any workaround?

When I touch/scroll the collection view, it populates with all of the nearby devices. I can clearly see in the code the binding being updated with each device, but it does not show on the screen. This does not happen in iOS devices.

Relevant log output

No response

@ISSPRO-Eng ISSPRO-Eng added the t/bug Something isn't working label Oct 31, 2024
@jfversluis
Copy link
Member

I can imagine the devices being scanned for happens in a background thread (on Android) and therefore it does not update the UI?

Have you tried adding an extra call to notify the property changed for the event, or invoke the adding of the new device on the main thread?

@jfversluis jfversluis added platform/android 🤖 s/needs-info Issue needs more info from the author area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Nov 1, 2024
@ISSPRO-Eng
Copy link
Author

ISSPRO-Eng commented Nov 1, 2024

I can imagine the devices being scanned for happens in a background thread (on Android) and therefore it does not update the UI?

Have you tried adding an extra call to notify the property changed for the event, or invoke the adding of the new device on the main thread?

I tried this.

MainThread.BeginInvokeOnMainThread(() => { _vm.AvailableDevices.Add(deviceObj); Console.WriteLine(device.Name); });.

I did try an extra call to notify the property changed as well to no avail. Any other options?

@jfversluis Just wondering what else to try?

@dotnet-policy-service dotnet-policy-service bot added s/needs-attention Issue has more information and needs another look and removed s/needs-info Issue needs more info from the author labels Nov 1, 2024
@mattleibow
Copy link
Member

What happens if you replace your item templates with a plain label or something super simple? Maybe it is a row layout issue somehow.

Also, maybe make the repo public if possible.

Another thing to try is to not use real scanning to get devices, just add a fake device on some button click and see if that renders. It may be that the UI is struggling to update from the scanning...

@mattleibow mattleibow added this to the Backlog milestone Nov 12, 2024
@mattleibow mattleibow added s/needs-info Issue needs more info from the author and removed s/needs-attention Issue has more information and needs another look labels Nov 12, 2024
Copy link
Contributor

Hi @ISSPRO-Eng. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView platform/android 🤖 s/needs-info Issue needs more info from the author t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants