public async void RefreshServices()
        {
            IsBusy = true;
            DetectedServices.Clear();
            try
            {
                IList <IService> services = await _microbit.GetServicesAsync();

                foreach (IService service in services)
                {
                    IMicrobitServiceProvider microbitServiceProvider =
                        IdToServiceProviderMappingProvider.ServiceProvider(service);
                    if (microbitServiceProvider != null)
                    {
                        DetectedServices.Add(microbitServiceProvider);
                    }
                }
            }
            catch (Exception e)
            {
                await Application.Current.MainPage.DisplayAlert("Exception", e.Message, "Ok");
            }
            finally
            {
                IsBusy = false;
            }
        }
        async void ServicesList_ItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            if (e.SelectedItem == null)
            {
                return;
            }

            IMicrobitServiceProvider serviceProvider = e.SelectedItem as IMicrobitServiceProvider;
            await Navigation.PushAsync(serviceProvider.GetServiceInstance().Page);

            ((ListView)sender).SelectedItem = null;
        }
        public DeviceServicesViewModel(IDevice device)
        {
            _microbit    = device;
            _bluetoothLe = CrossBluetoothLE.Current;
            _adapter     = _bluetoothLe.Adapter;

            _adapter.DeviceConnected      += HandleConnectionStateChanged;
            _adapter.DeviceDisconnected   += HandleConnectionStateChanged;
            _adapter.DeviceConnectionLost += HandleConnectionStateChanged;

            ToggleConnectionCommand = new Command(
                () =>
            {
                if (_microbit.State == DeviceState.Connected)
                {
                    Disconnect();
                }
                else if (_microbit.State == DeviceState.Disconnected)
                {
                    Connect();
                }
            },
                () => !IsBusy);

            ServicesCommand = new Command(async() =>
            {
                DetectedServices.Clear();
                IList <IService> services = await _microbit.GetServicesAsync();
                foreach (IService service in services)
                {
                    IMicrobitServiceProvider microbitServiceProvider = IdToServiceProviderMappingProvider.ServiceProvider(service);
                    if (microbitServiceProvider != null)
                    {
                        DetectedServices.Add(microbitServiceProvider);
                    }
                }
            }, () => !IsBusy
                                          );

            DetectedServices = new ObservableCollection <IMicrobitServiceProvider>();
        }