Xamarin forms Selected Item in List

62 Views Asked by At

Im trying to create project with Bluetooth connection. But when i'm trying to select item in list there are no message: "Do you want to connect to this device?"

enter image description here

I manually added the BMW X5 device, but when I click on it, no windows with messages appear

It it my DevicesList_OnItemSelected event:

 private async void DevicesList_OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (DevicesList.SelectedItem == null)
            {
                await DisplayAlert("Error", "Please select a device from the list first.", "OK");
                return;
            }

            CurDevice = DevicesList.SelectedItem as IDevice;

            if (CurDevice != null)
            {
                if (CurDevice.State == DeviceState.Disconnected)
                {
                    var result = await DisplayAlert("Message", "Do you want to connect to this device?", "Connect", "Cancel");
                    if (result)
                    {
                        try
                        {
                            await Adapter.ConnectToDeviceAsync(CurDevice);
                            await DisplayAlert("Message", "Connected to device with Id: " + CurDevice.Id, "OK");
                        }
                        catch (DeviceConnectionException ex)
                        {
                            await DisplayAlert("Error", ex.Message, "OK");
                        }
                    }
                }
                else
                {
                    await DisplayAlert("Error", "Device is already connected or being connected", "OK");
                }
            }
        }

`

0

There are 0 best solutions below