//private async void AppBarButtonEmail_Click(object sender, RoutedEventArgs e)
        //{
        //    var emailMessage = new Windows.ApplicationModel.Email.EmailMessage();
        //    emailMessage.Body = "";
        //    emailMessage.Subject = _device.Name;

        //    await _progressbar.ShowAsync();
        //    emailMessage.Body=await DumpDeviceInfo();
        //    await _progressbar.HideAsync();
        //    await Windows.ApplicationModel.Email.EmailManager.ShowComposeNewEmailAsync(emailMessage);
        //}

        private async Task <string> DumpDeviceInfo()
        {
            StringBuilder sb = new StringBuilder();

            try
            {
                sb.Append("Device: " + _device.Name + Environment.NewLine);
                sb.Append("Id: " + _idDevice + Environment.NewLine);
                sb.Append("Address: " + BLEHelper.AddressToString(_device.BluetoothAddress) + Environment.NewLine);
                sb.Append(Environment.NewLine);
                sb.Append("Services:" + Environment.NewLine);

                foreach (var s in _services)
                {
                    sb.Append(Environment.NewLine);
                    sb.Append("Service: " + (string)cUToName.Convert(s.Uuid, typeof(string), null, null) + Environment.NewLine);
                    sb.Append("UUID: " + s.Uuid + Environment.NewLine);
                    foreach (var c in s.GetAllCharacteristics())
                    {
                        sb.Append(Environment.NewLine);
                        sb.Append("Characteristic: " + ((string)cCName.Convert(c, typeof(string), null, null)).Replace("\0", "") + Environment.NewLine);
                        sb.Append("UUID: " + c.Uuid + Environment.NewLine);
                        sb.Append((string)cCharacteristicProperties.Convert(c, typeof(string), null, null) + Environment.NewLine);

                        if (((int)c.CharacteristicProperties & (int)GattCharacteristicProperties.Read) != 0)
                        {
                            try
                            {
                                GattReadResult readResult = await c.ReadValueAsync();

                                if (readResult.Status == GattCommunicationStatus.Success)
                                {
                                    var value = new byte[readResult.Value.Length];
                                    DataReader.FromBuffer(readResult.Value).ReadBytes(value);
                                    sb.Append((string)cByteToString.Convert(value, typeof(string), null, null) + Environment.NewLine);
                                    sb.Append(((string)cByteToText.Convert(value, typeof(string), null, null)).Replace("\0", "") + Environment.NewLine);
                                }
                            }
                            catch (Exception ex) {
                                int kk = 0;
                            }
                        }
                    }
                    sb.Append(Environment.NewLine);
                }
            }
            catch
            {
            }
            return(sb.ToString());
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            _progressbar = StatusBar.GetForCurrentView().ProgressIndicator;

            await _progressbar.ShowAsync();

            if ((e.Parameter != null) && (e.Parameter.GetType() == typeof(DeviceInformation)))
            {
                try
                {
                    _idDevice = ((DeviceInformation)e.Parameter).Id;
                    _device   = await BluetoothLEDevice.FromIdAsync(((DeviceInformation)e.Parameter).Id);

                    this.lblDeviceName.Text = ((DeviceInformation)e.Parameter).Name + " " + BLEHelper.AddressToString(_device.BluetoothAddress);
                    if (_device == null)
                    {
                        new MessageDialog("Could not connect to the selected device!", "Error").ShowAsync();
                    }

                    _services = _device.GattServices;
                    lstServices.ItemsSource = _services;
                }
                catch (Exception ex)
                {
                    new MessageDialog("Device enumeration error: " + ex.Message, "Error").ShowAsync();
                }
            }
            this.navigationHelper.OnNavigatedTo(e);
            await _progressbar.HideAsync();

            _dataTransferManager = DataTransferManager.GetForCurrentView();
            _dataTransferManager.DataRequested += OnDataRequested;
        }