async void BoardsCollectionView_SelectionChanged(System.Object sender, Xamarin.Forms.SelectionChangedEventArgs e) { Debug.WriteLine("BoardsCollectionView_SelectionChanged"); if (e.CurrentSelection == null || e.CurrentSelection.Count == 0) { return; } if (sender is CollectionView collectionView) { collectionView.SelectedItem = null; } if (e.CurrentSelection[0] is OWBaseBoard baseBoard) { if (baseBoard.IsAvailable) { StopScanning(); //_selectedBoard = board; var cancellationTokenSource = new CancellationTokenSource(); var connectingAlert = new Popup.ConnectingAlert(baseBoard.Name, new Command(() => { Debug.WriteLine("Connecting alert: cancel clicked"); if (cancellationTokenSource.IsCancellationRequested == false) { cancellationTokenSource.Cancel(); //_selectedBoard = null; //App.Current.OWBLE.Disconnect(); } })); await PopupNavigation.Instance.PushAsync(connectingAlert, true); var board = await App.Current.ConnectToBoard(baseBoard, cancellationTokenSource.Token); await PopupNavigation.Instance.PopAllAsync(); if (board != null) { await Navigation.PushModalAsync(new Xamarin.Forms.NavigationPage(new BoardPage(board))); // Publish notification that board was connected IWatch watchService = DependencyService.Get <IWatch>(); watchService.ListenForWatchMessages(board); } /* * try * { * var connectTask = App.Current.OWBLE.Connect(_selectedBoard); * * var connected = await connectTask; * } * catch (TaskCanceledException) * { * _selectedBoard = null; * Hud.Dismiss(); * } * catch (Exception) * { * await DisplayAlert("Error", $"Unable to connect to {board.Name}.", "Cancel"); * } */ } else { var alert = new Pages.Popup.Alert("Error", $"{baseBoard.Name} is not available."); await PopupNavigation.Instance.PushAsync(alert, true); } } }